I have a data table .I want to convert my data table into string array.
- data table dt=new data table();
- string[] array=dt;
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Dilip GuptaPosted Jan 2, 2017, 2:55 AM
Dinesh SanthalingamPosted Jan 2, 2017, 2:40 AM
Dilip GuptaPosted Jan 2, 2017, 2:25 AM
string[] userArr = new string[dt.Rows.Count];
for( int i = 0; i < dt.Rows.Count; i++)
{
userArr[i] = dt.Rows[i][columnIndex].ToString();
}
Dinesh SanthalingamPosted Jan 2, 2017, 2:15 AM
Amit Singh.
Amit Kumar SinghPosted Jan 2, 2017, 1:49 AM
Try this (LINQ method syntax):
or in LINQ Query syntax:
Castis required, because Columns is of type DataColumnCollection which is aIEnumerable, notIEnumerable. The other parts should be obvious.