Records accessed not in order

jasper87

New member
Joined
Sep 29, 2010
Messages
2
Programming Experience
1-3
Im accessing database(ms access table) using the OleDb.OleDbConnection.
I can sucessfully access each record in the database .

Unfortunately I cannot access them in order. This means that row zero in the table and row zero in the dataset are not pointing to the value. For example, i can access row 0 colomn 3 in the table using the command :

ds.Tables("filename").Rows(3)Item(3) instead of ds.Tables("filename").Rows(0)Item(3)

Can anyone please tell me how to solve this problem
Thanks
 
Don't you get an intellisense warning that "comma or a valid expression continuation is expected" ?
VB.NET:
ds.Tables("filename").Rows(0)[COLOR="#ff0000"].[/COLOR]Item(3)

However if it's typo and you have the dot over there it should work. means Rows(0) refers the very first row in the datatable.
 
Thanx Kulrom

But the problem is not with the dot, the problem is that whenever I want to display Row(0) using the above command which is like you said, the first row of the table, what I get is row 3 being displayed instead of row 1 . This means that the VB is accessing the database in random order instead of sequential order. How do I solve this problem

Thanx alot Kulrom,
Your opinion is deeply appreciated
 
You should never expect the rows in a DataTable to be in any kind of order. If you want order, set the DefaultView of the table to have some order, and access your rows through that:

myDataTable.DefaultView.Sort = "[someColumn] DESC, [otherolumn] ASC"
myDataTable.DefaultView(0).Row 'access the row at 0

Remember, DefaultView is just a DataView, you can also make multiple views to sit on one table if you need to order differently simultaneously

I'll repeat, just incase you skipped the importance of it the first time.. Never, ever rely on or assume that the rows in a DataTable will ever be in any particular order, not even the order they were downloaded from the database in. Always, always, always apply a proper sort to the data using a DataView if you intend to address rows by their positions
 
Back
Top