duxfox-- duxfox-- - 5 months ago 51
C# Question

datatable get specific column from row

I have the following:

//a datatable with some rows and columns lets say 5x5
var datatable = new DataTable();
var numberofrows = datatable.rows.count;

for (int i = 0; i < numberofrows; i++) {
//for each row, get the 3rd column
var cell = datatable.rows[i].???

how do I get the 3rd column for each row?


for 3rd column

var cellValue = datatable.Rows[i][2];

better, if you know the column name,

var cellValue = datatable.Rows[i]["name"];