Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

datatable get specific column from row

Tags:

c#

datatable

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?

like image 518
duxfox-- Avatar asked Dec 19 '22 06:12

duxfox--


1 Answers

for 3rd column

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

better, if you know the column name,

var cellValue = datatable.Rows[i]["column_name"];
like image 181
Yogee Avatar answered Jan 01 '23 18:01

Yogee