今天 做一个小程序 ,遇到了这样一个 问题就是 怎样简单的 遍历一个 DataTable 
一、

DataTable table= DBhelper.GetDataTable(str);
foreach( DataRow row in table.Rows )//得到行集合
{
    foreach( object col in row.ItemArray )//得到列集合
    {
        MessageBox.Show(col.ToString());
    }
}

二、

DataTable tempTable = DBhelper.GetDataTable(str);
foreach( DataRow row in tempTable.Rows )
{
    foreach( DataColumn dc in row.Table.Columns )
    {
        MessageBox.Show (row[ dc ].ToString ());
    }
}

 

 

3 如何遍历DataSet  
 foreach(DataTable dt in dataSet.Tables) 
foreach(DataRow dr in dt.Rows) 
foreach(DataColumn dc in dr.Table.Columns) 
Console.WriteLine(dr[dc]);  

相关文章:

  • 2021-10-17
  • 2022-12-23
  • 2021-12-16
  • 2022-12-23
  • 2021-11-17
  • 2022-12-23
  • 2022-02-08
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-18
相关资源
相似解决方案