duxfox-- duxfox-- - 1 year ago 121
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?

Answer Source

for 3rd column

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

better, if you know the column name,

var cellValue = datatable.Rows[i]["name"];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download