Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 12-Jan-13 4:45am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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)) ...
  Permalink  
Comments
priyamtheone at 13-Jan-13 9:46am
   
@Mika: Exactly! I figured out the same way while fiddling around. But Thanks for the help anyways. Thumbs up!
Mika Wendelius at 13-Jan-13 10:18am
   
You're welcome :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

string Text = TextBox.Text.Split(new char[] { '\n' })[0];
  Permalink  
Comments
Mayank Topiwala at 13-Jan-13 0:48am
   
+5
priyamtheone at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 195
1 ProgramFOX 130
2 Maciej Los 105
3 Sergey Alexandrovich Kryukov 85
4 Afzaal Ahmad Zeeshan 82
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 13 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100