RE: Datatable Row Number by kh
kh
Thu May 11 09:29:03 CDT 2006
Do you mean the index of the row in the table's row collection?
If so, and the data is unique, then you could use DataTable.Select() to find
the row matching your criteria and then get the index of this row within the
collection, as follows. Note Select() returns an array or rows matching the
specified criteria, hence the indexer:
// create a table
DataTable dt = new DataTable();
dt.Columns.Add("MyColumn", typeof(string));
// add some data
dt.Rows.Add(new object[] { "Hello" });
dt.Rows.Add(new object[] { "World" });
// find a row
int rowIndex = dt.Rows.IndexOf(dt.Select("MyColumn = 'World'")[0]);
hth
kh