简体   繁体   中英

How do I wrap a text in SQL Server database?

As shown in the photo, a cell in the dataGridView contains 2 lines and when I insert it into the Database it doesn't wrap. I checked the wrap option in Tools --> options --> Test Editor --> all Language --> word wrap. But the word wrap still not working. As you can see the wrapped line in the DataGridView becomes one line in the database. Any idea in how can I wrap the line?

I used this code to insert data from DataGridView into SQL Server database:

private void button9_Click(object sender, EventArgs e)
{
    SqlConnection cn = new SqlConnection("Data Source=PCN-TOSH;Initial    Catalog=mydb;Integrated Security=True");

    cn.Open();
    SqlCommand cm = new SqlCommand("Insert into Customer(Qty, Des, Price) values ('" + dataGridView1.Rows[0].Cells[0].Value + "', '" + dataGridView1.Rows[0].Cells[1].Value + "','" + dataGridView1.Rows[0].Cells[2].Value + "')");
    cm.Connection = cn;
    cm.ExecuteNonQuery();
    cn.Close();
}

照片

It doesn't matter very much how your value is rendered by SQL Server Mgmt Studio's (SMMS's) result set viewer. That program has pretty basic abilities to display multi line text.

The real question is whether the value renders correctly in your application program after a round trip to the data base. If it does, all is well.

If it doesn't, you should try to figure out whether the information is being altered on the way to the database, or the way back.

I have often succeeded at that by using Copy to copy the text from SMMS, and then I paste it into a simple text editor. Then I drag the cursor to count spaces.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM