如何获取保存在数据库中的多行文本字段的第一行? [英] How to get the first line of a multiline text field saved in database?

查看:86
本文介绍了如何获取保存在数据库中的多行文本字段的第一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多行文本框,其文本保存到数据库中。现在我只需要显示要在datagridview中显示的文本的第一行。我该怎么办?

I have a multi-line textbox whose text is saved into database. Now I need to show only the first line of the text to be shown in a datagridview. How can I do it?

推荐答案

一种方法是使用 CHARINDEX [ ^ ]找到新行并将其用于 SUBSTRING [ ^ ]。



所以类似

One way is to use CHARINDEX[^] to find the new line and use that to for SUBSTRING[^].

So something like
SELECT SUBSTRING( MyColumn, 1, CHARINDEX( CHAR(10), MyColumn)) ...


string Text = TextBox.Text.Split(new char[] { ''\n'' })[0];


在表格中创建一列,并将多行文字的第一行插入其中然后将datagridview绑定到这个新列。
Create a column in your table and insert the first line of the multiline text into it then bind your datagridview to this new column.


这篇关于如何获取保存在数据库中的多行文本字段的第一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆