1

I have a multilined textbox on my Winform. I want to INSERT it into my column in SQL Server. Does this automatically add the new lines into my column? Or is this even possible? BTW NVARCHAR(MAX) is the datatype of my column.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
vicserna1997
  • 97
  • 1
  • 7

2 Answers2

0

The NVARCHAR(MAX) saves row breaks and should work with multilined textbox. See here for an example.

ZarX
  • 1,096
  • 9
  • 17
  • It doesn't have to be a `MAX`, any length `(n)(var)char` can store the characters for a Carriage Return (ASCII code 13) and a Line Break (ASCII code 10). – Thom A Feb 02 '19 at 18:41
0

It should be no different than any other text insert -- it's just that this text may (or may not) contain newline characters:

using (SqlCommand cmd = new SqlCommand(
    "insert into MyTable (BigTestField) values (@TEXTBOX_DATA)", conn))
{
    cmd.Parameters.Add(new SqlParameter("@TEXTBOX_DATA", SqlDbType.NVarChar));
    cmd.Parameters[0].Value = textbox.Text;

    cmd.ExecuteNonQuery();
}
Hambone
  • 15,600
  • 8
  • 46
  • 69