How to iterate all items in a given row in the DataTable

后端 未结 4 1390
眼角桃花
眼角桃花 2020-12-20 14:26

How to iterate all items in a given row in the DataTable . I have the following code to iterate all rows, I want another For loop to iterate all ce

4条回答
  •  死守一世寂寞
    2020-12-20 15:16

    You have to loop through DataRow.ItemArray. In C#, we can do it by following code:

     foreach (DataRow dr in dt.Rows)
       {
         foreach (var item in dr.ItemArray)
           {
                    Console.WriteLine(item);
           }
       }
    

    This is equivalent to the following VB.NET code.

    For Each dr As DataRow In dt.Rows
        For Each item In dr.ItemArray
            Console.WriteLine(item)
        Next
    Next
    

提交回复
热议问题