开发者

How to add DataRow in string of arrray

In the DataTable i have n number rows want add those rows in arra开发者_开发百科y?


DataTable tbl = new DataTable();
tbl.Rows

Rows is array of your records...


The code below stores all the information in a datatable in a double array of strings. The code should be plug-and-play, just make sure you swap out "dataTable1" with the name of your actual DataTable.

string[,] stringArray = new string[dataTable1.Rows.Count, dataTable1.Columns.Count];

for (int row = 0; row < dataTable1.Rows.Count; ++row)
{
   for (int col = 0; col < dataTable1.Columns.Count; col++)
   {
      stringArray[row, col] = dataTable1.Rows[row][col].ToString();
   }
}

To access the first item out of stringArray, simply use call the code below, using the indices as you would for a normal array.

stringArray[0, 0]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜