Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get value of datarow in c#

Tags:

c#

I have a question regarding DataRows. I have a DataTable which I then converted into a list of DataRow's. Now I want the string information stored in each DataRow. How can I do this? This is my code:

List<DataRow> list = dt.AsEnumerable().ToList();
like image 673
Ryan Avatar asked Jun 27 '11 19:06

Ryan


1 Answers

You could do this,

foreach(var row in list)
{
    var value = row["ColumnName"] as string;
}

or this to get all string values of "ColumnName" lazily.

var values = list.Select(row => row["ColumnName"] as string);

Why would you turn a DataTable into a list, though? Just wondering.

like image 183
Samantha Branham Avatar answered Oct 10 '22 04:10

Samantha Branham