Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I would like to assign datatable values to variable that i have declared.

Can anyone help me with that..
Thanks in advance.
Posted
Comments
joshrduncan2012 5-Aug-13 9:26am    
Help you with what? What have you tried to do to accomplish this? Where are you stuck?

You may want to refer to the documentation online, for example http://msdn.microsoft.com/en-us/library/system.data.datatable.rows.aspx[^]

You can do like this:
C#
DataTable dt;
...
String value = dt.Rows[0][1].ToString();  // second column of the first row
 
Share this answer
 
Comments
Dukesta8402 6-Aug-13 3:18am    
Thanks that worked well..
ZurdoDev 6-Aug-13 7:12am    
Glad to hear it.
Do something like:
C#
Object o = dataTable.Rows[0]["ColumnNameOrIndex"];
String value = Convert.ToString(o);

Hope that would help you.
 
Share this answer
 
Comments
Dukesta8402 6-Aug-13 3:17am    
Thanks guys that helped out...

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