Access cell value of datatable Access cell value of datatable asp.net asp.net

Access cell value of datatable


If you need a weak reference to the cell value:

object field = d.Rows[0][3]

or

object field = d.Rows[0].ItemArray[3]

Should do it

If you need a strongly typed reference (string in your case) you can use the DataRowExtensions.Field extension method:

string field = d.Rows[0].Field<string>(3);

(make sure System.Data is in listed in the namespaces in this case)

Indexes are 0 based so we first access the first row (0) and then the 4th column in this row (3)


string abc= dt.Rows[0]["column name"].ToString();


You can also try (first cell in 4th column):

dt.Rows[0][3]