Reputation: 576
I am trying to get a value from a DataRow
in a specific column in a DataTable
. It should return values like "abc12345", but instead returns "ListViewSubItem: {abc12345}", according to the debugger. Why is this?
foreach (DataRow row in itemsTable.Rows)
{
// the required data is in the first column of the DataTable
// both of the following have been tried:
string myValue = row[0].ToString();
string myValue = row.Field<string>(0);
}
Upvotes: 0
Views: 858
Reputation: 1
You are doing it wrong. It should be string myValue = row[columnIndex].Text;
and you are trying to get the value of the first column. You can use row["columnName"]
also .
Note: I have used Text
property.
Upvotes: 1