简体   繁体   English

如何在 SQL Server 数据库中换行文本?

[英]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.如图所示, dataGridView中的一个单元格包含 2 行,当我将其插入数据库时​​,它不会换行。 I checked the wrap option in Tools --> options --> Test Editor --> all Language --> word wrap.我在Tools --> options --> Test Editor --> all Language --> word wrap.检查了换行选项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.如您所见,DataGridView 中的换行行变成了数据库中的一行。 Any idea in how can I wrap the line?知道如何包装线路吗?

I used this code to insert data from DataGridView into SQL Server database:我使用此代码将数据从 DataGridView 插入 SQL Server 数据库:

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. SQL Server Mgmt Studio (SMMS) 结果集查看器如何呈现您的值并不重要。 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.我经常成功地通过使用 Copy 从 SMMS 复制文本,然后将其粘贴到一个简单的文本编辑器中。 Then I drag the cursor to count spaces.然后我拖动光标来计算空格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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