Georges Oates Larsen
Georges Oates Larsen

Reputation: 7092

C# Datatable woes

I have a database command that populates a DataTable I want to get the value of an entry in the Datatable, based on, A: The numeral index of the row, and b, the string name of the column. That's all I want, how is that possible?

Upvotes: 1

Views: 128

Answers (3)

IAbstract
IAbstract

Reputation: 19881

DataTable dt = GetData();
var result = dt.Rows[RowIndex]["MyColumnName"];

The RowIndex is an indexed property of the datatable which returns a DataRow. "MyColumnName" is an indexed property of the DataRow, returning the value as an object.

Upvotes: 0

saus
saus

Reputation: 2174

yourDatatable.Rows[rowIndex]["columnName"] should work

Upvotes: 2

Nick Rolando
Nick Rolando

Reputation: 26167

myTbl.Rows[0]["b"];

A is not a row index.

Upvotes: 1

Related Questions