How do You Get a Specific Value From a System.Data.DataTable Object? How do You Get a Specific Value From a System.Data.DataTable Object? database database

How do You Get a Specific Value From a System.Data.DataTable Object?


Just the basics....

yourDataTable.Rows[ndx][column]

where ndx is the row number (starting at 0)where column can be a DataColumn object, an index (column n), or the name of the column (a string)

yourDataTable.Rows[0][0]yourDataTable.Rows[0][ColumObject]yourDataTable.Rows[0]["ColumnName"]

to test for null, compare to DBNull.Value;


You mean like table.Rows[0]["MyColumnName"]?


If you wan't to extract the row with it's ID = 5(ie the Primary key) and get its value for the Column called Description.

DataRow dr = myDataTable.Rows.Find(5);String s = dr["Description"].ToString();