Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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?
Posted

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

So something like
SQL
SELECT SUBSTRING( MyColumn, 1, CHARINDEX( CHAR(10), MyColumn)) ...
 
Share this answer
 
Comments
priyamtheone 13-Jan-13 9:46am    
@Mika: Exactly! I figured out the same way while fiddling around. But Thanks for the help anyways. Thumbs up!
Wendelius 13-Jan-13 10:18am    
You're welcome :)
string Text = TextBox.Text.Split(new char[] { '\n' })[0];
 
Share this answer
 
Comments
Mayank Topiwala 13-Jan-13 0:48am    
+5
priyamtheone 13-Jan-13 9:43am    
@_Subrata_: May be I wasn't clear but I wanted to save the multi-line text from the textbox to the database and later, obtain just the first line of it from the database.
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900