Displaying data of data table

大城市里の小女人 提交于 2019-12-04 04:16:55

I still can't post a comment but here is a quick answer:

 foreach(DataRow row in myTopTenData.Rows)
 { 
     string ID  = row["ColumnID"].ToString();
     string Name= row["columnName"].ToString();
     string FamilyName= row["ColumnFamilyName"].ToString();    
 }

Make sure to check for null values when retrieving the data

Assuming that myTopTenData is a DataTable then you loop on rows of a datatable in this way

foreach (DataRow row in myTopTenData.Rows)
{
     Console.WriteLine();
     for(int x = 0; x < myTopTenData.Columns.Count; x++)
     {
          Console.Write(row[x].ToString() + " ");
     }
}

Of course this snippet should be taken only as a trivial example.
You need to consider null values and a robust error checking.

you can use Datagrid to display your DataTable like this :

in Wpf :

datagrid.SetBinding(ItemsControl.ItemsSourceProperty, new System.Windows.Data.Binding { Source = dt});

========================================================================

in winform :

datagrid.DataSource(datatable);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!