Hi All,
I am using a datatable to store some data from the xml.
I need the row number where a particular string exists
(Note: All values in datatable are unique).
Please help me in this regard.

Re: Datatable Row Number by FUnky

FUnky
Thu May 11 02:46:50 CDT 2006


"GhanaShyam" <GhanaShyam@discussions.microsoft.com> wrote in message
news:9A2C6105-1857-479C-AE2D-F2C8F5329EA4@microsoft.com...
> Hi All,
> I am using a datatable to store some data from the xml.
> I need the row number where a particular string exists
> (Note: All values in datatable are unique).
> Please help me in this regard.

There is no row index property as such.
A possible workaround is using a counter, looping through the datatable,
incrementing the counter until the desired row is reached.

FUnky



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