Click here to Skip to main content
12,241,599 members (47,750 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# VB .NET SQL-Server VB.NET , +
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 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 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 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.
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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 13 Jan 2013
Copyright © CodeProject, 1999-2016
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