Do as Espen suggested and then go somewhat like this:
...
String myTextBoxTextWithCarriageReturns = textBox1.Text;
bool success = WriteTextBoxData(someConnectionString, myTextBoxTextWithCarriageReturns);
...
private bool WriteTextBoxData(String connectionString, String text)
{
bool retVal = true;
string queryString = "INSERT INTO TextData text VALUES(@text)";
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(queryString, connection);
command.Parameters.Add(new SqlParameter("text", SqlDbType.VarChar,100).Value = text);
try
{
connection.Open();
command.ExectueNonQuery();
}
catch(Exception ex)
{
retVal = false;
}
finally
{
connection.Close();
}
}
return retVal;
}
My code assumes that the field in the DB is type varchar(100), so some adjustments might have to be made (i.e. primary key etc.). This code works even if the text has carriage returns in it as the parameter is passed with the SqlParameters class. This class does the right encoding so that valid SQL is generated. If you build the SQL statement by hand you would have to encode the CRs yourself.
Hope that helps!
Best Regards,
Manfred