Click here to Skip to main content
16,017,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All Please Help me,
I Have DataTable in the below:

===============
NO | Name     |
---------------
1  | Jhon     |
---------------
2  | Wayne    |
---------------
3  | Robert   |


i want to take the All list and and save it in the variable sting.

i'm use this code :

C#
sTagValue1 = cbxparameter.SelectedValue.ToString();
           SqlDataAdapter da = new SqlDataAdapter(("select * from Table"), oSqlConn);
           DataTable dt = new DataTable();
           da.Fill(dtformid);
           sVariable =dt.Rows[?][?].ToString();//this my problem....
Posted
Updated 24-Jan-15 5:39am
v2

Not sure if I understood your question correctly but if you want to get a single string variable containing all the names (with delimiter perhaps) then try something like:
C#
string sVariable = string.Join(",", dt.AsEnumerable().Select(x => x["Name"].ToString()));

Just remember to define
C#
using System.Data;

in order to be able to use the LINQ methods.
 
Share this answer
 
Comments
Member 11057420 25-Jan-15 2:20am    
Mika, Thax you, this solved my problem......
Wendelius 25-Jan-15 4:03am    
You're welcome :)
Member 11057420 25-Jan-15 21:35pm    
mika,
im follow your way and i get this data = TED000, TED001, TED002
and how if i want get data like 'TED000', 'TED001', 'TED003'
Wendelius 25-Jan-15 23:38pm    
Just modify the select portion of the statement. Something like:
string sVariable = string.Join(",", dt.AsEnumerable().Select(x => "'" + x["Name"].ToString() + "'"));
Member 11057420 26-Jan-15 1:22am    
@mika,great
thx u very much mika for your respon :-)
What you are asking for doesn't really match your code: If you want to get a list of the Names from the DataTable, then that's pretty easy if you use Linq methods:
C#
List<string> list = dt.AsEnumerable().Select(r => r["Name"].ToString()).ToList();


[edit]HTML encode, damn it![/edit]
 
Share this answer
 
v2

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