Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check dataset for row number

Status
Not open for further replies.

mjd3000

Programmer
Apr 11, 2009
136
GB
What is the correct syntax to check which row in a dataset you are currently looking at?

I tried this, but it doesn't work :

if (ds.Tables[0].Row == 1)
{

}
 
ds.Tables[0] is a reference to the first table in the collection of tables as part of the DataSet(ds) so this is a valid statement
var table = ds.Tables[0];

however DataTable does not have a member Row. It does have a member named Rows. This is a collection of all the rows in the table.

you can get an exact row in the table like this
var row = ds.Tables[0].Rows[x];
where x in the zero based index of the row you want.

if you want to know what row you are on you can loop through the rows.
var index = 0;
foreach(var row in table.Rows)
{
Console.WriteLine("the current row index is {0}", index++);
}

most times you shouldn't care what the row index is, you just want to find the row and continue processing.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top