Mr_Fulano
asked on
DataTable.Rows.FIND
Hi, I have a VB 2005 Windows Application using an Access 2003 database.
In my application, I've creating a dataTable called "dtUsers" and am filling it with all the fields from the "Users" Table. I would like to use the FIND property to search the dataTable for a specific User's Last Name. I know I can loop through all the rows one at a time until I find a match, but that seems extremely inefficient.
If dtUsers.Rows.Find("LastNam e") = "Finklestinkle" Then
Console.WriteLine("I found him...!!!")
End If
I think the syntax may be wrong, and it keeps telling me the dataTable does not have a Primary Key.
Any suggestions or tutorials that might help?
Thank,
Fulano
In my application, I've creating a dataTable called "dtUsers" and am filling it with all the fields from the "Users" Table. I would like to use the FIND property to search the dataTable for a specific User's Last Name. I know I can loop through all the rows one at a time until I find a match, but that seems extremely inefficient.
If dtUsers.Rows.Find("LastNam
Console.WriteLine("I found him...!!!")
End If
I think the syntax may be wrong, and it keeps telling me the dataTable does not have a Primary Key.
Any suggestions or tutorials that might help?
Thank,
Fulano
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
First and foremost, thank you both VERY much. Each of you provided excellent advice. -- Its times like this when I wish the points were unlimited, but in all honesty and fairness, I was able to use Rachitkohli's suggestion to solve my problem and he also answered first. So, I will award the full amount to Rachitkohli.
Thanks,
Fulano
Thanks,
Fulano
An alternative is to use the Select() method. It would look like this:
dtUsers.Select("LastName = 'Finklestinkle')
If all you wanted was to know if there was a match, you could use it this way
if dtUsers.Select("LastName = 'Finklestinkle').Rows.Coun