|
-
Jul 26th, 2005, 08:58 AM
#1
Thread Starter
Junior Member
[RESOLVED] Quickest way to locate a record within a dataset
Hi,
I would like to know what the quickest way is to return the record number of a record within a dataset.
i am trying to locate the record by using a column that will be holding unique data but is not the records primary key.
At the moment i am filling the dataset and then using the rows.count method to get the amount of records. Then using a for i = 0 to count-1 loop to check the condition i am looking for. when it meets the criteria the record number will equal the variable i (where i jump out of the for next loop)allowing me to access that record using dataset.tables(0).rows(i)("fieldname") for the fields within the record
Now whilst this works fine i am currently only dealing with quite small amounts of data and was wondering if there was a better/quicker way of doing it.
Thanks alot
Last edited by CptCarter; Jul 27th, 2005 at 04:12 AM.
-
Jul 26th, 2005, 09:08 AM
#2
Re: Quickest way to locate a record within a dataset
You can get the actual row using the Select method of the DataTable class, which returns an array of DataRows that match an SQL WHERE clause, e.g.:
Code:
Dim myRows As DataRow() = myTable.Select("Name LIKE 'a%'")
-
Jul 26th, 2005, 10:02 AM
#3
Thread Starter
Junior Member
Re: Quickest way to locate a record within a dataset
Thanks for the reply.
That does look like a quick way to get the record i would need.
However if i make changes to some of the fields within that record how could i move the changes back to the original record within the dataset without having to loop through the dataset to find the record number.
Cheers
-
Jul 26th, 2005, 10:07 AM
#4
Re: Quickest way to locate a record within a dataset
Should be automagic... I don't think it actualy makes a copy of anything, just references to the original record. So by changing the fields in myRows, it should be automagicaly done in the parent dataset. At least in theory that's how I would expect it happen... haven't had the opportunity to actualy try it.
Tg
-
Jul 26th, 2005, 06:31 PM
#5
Re: Quickest way to locate a record within a dataset
As techgnome says. The Select method gets an array of references to the actual DataRows themselves. Just like any reference-type objects, you can have as many references to the same DataRow as you like. This fact is probably the reason that the rows are returned in an array and not a table, because a DataRow can only belong to one DataTable at a time.
-
Jul 27th, 2005, 04:10 AM
#6
Thread Starter
Junior Member
Re: Quickest way to locate a record within a dataset
Thanks for the replies.
That should prove alot quicker than the method i was using before.
-
Aug 17th, 2005, 08:29 AM
#7
Frenzied Member
Re: [RESOLVED] Quickest way to locate a record within a dataset
but with this array of data, how can I get the absolute row position of this data row? For example, my controls are not bound, and I've edited the data for the field by which the table was ordered. Now, of course the order changes for all, so I removed the table and reloaded it (i'm sure there's a faster way), and now, having stored the primary key value for the edited row in a variable, I want to jump to that row to populate my controls again
Wen Gang, Programmer
VB6, QB, HTML, ASP, VBScript, Visual C++, Java
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|