[ACCEPTED]-How do You Get a Specific Value From a System.Data.DataTable Object?-system.data

Accepted answer
Score: 11

Just the basics....

yourDataTable.Rows[ndx][column]

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

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

to 1 test for null, compare to DBNull.Value;

Score: 1

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

0

Score: 0

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

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

More Related questions