Finding last row in the dataset

minn

Active member
Joined
Apr 10, 2006
Messages
37
Programming Experience
Beginner
Hello,

I wish to have a loop that looks through each row in the dataset and compares the values to that in a textbox.

To do this, i need to tell the loop to keep going until it reaches the last row of the dataset. How do I specify in my code the position of the last row of a dataset?

Please help!
Thanks in advance
 
It'll be the DataTable you are talking about and here's how you do it...

VB.NET:
For Each Dr as datarow In 'YourDataTable'.rows
 
.....
 
next
or

VB.NET:
For i as integer = 0 to 'YourDataTable'.Rows.Count-1
 
...
 
next
 
Thanks mate,

my data is in a dataset so will i need to change my code to reflect a dataset rather than datarow?
 
No, your data is in a datatable. There is a common mis-conception that a Dataset holds the information from the database. Think of it in terms like this....


MS Access is a Database Management System..

The equivalent to that in ADO.Net is a 'System.Data.Dataset' Just a lot more scaled down.
------------------------------------------------------------------------
MS Access can have a number of Tables....

ADO.Net equivalent...

System.Data.Datatable


So when you say your data is in a dataset it's like saying.. i've put my data in Microsoft Access and i didn't even use a table!!
You can't, i'm not trying to be flippent it's just important that you understand the difference.

my data is in a dataset so will i need to change my code to reflect a dataset rather than datarow?

To clarify.....

Your Datatable is in your DataSet, a dataset can hold a number of datatables for creating relationships and such. Your data is in a datatable, in the datatable is a collection of datarow objects that reflect the rows in your Database also in your datatable is a collection of DataColumn objects that reflect the fields in your database table. To further complicate this issue, a datatable doesn't have to belong to a Dataset. For example if you are only using one database query and returning a result from one Table in yuor database then you would'nt need a Dataset, You could use a datatable on it's own.

You can iterate through the DataTable Collection, the Datarow collection, or the DataColumn collection with the code i have provided above. You just need to substitute with the collection you want to search through.

With Me? I think i may have answered you question. But if you'd like further clarification then just ask.
 
Back
Top