SELECT & COMPARE database column entries !
-
Hi All, I have 600 rows entries in a SQL database column "Name". At present I am looping through each row and searching for a text which should match the entries in "Name" column. My code is like this: For Each dr As DataRow In myDataSet.Tables(0).Rows If Trim(dr(("Name"))) = Trim(search_text) Then ' matching found... End If Next above, myDataSet contains the "Name" column data. Now, the above code is very time consuming, because it has to loop entire 600 times... What I am looking is any simple method, by which it direct jumps into the matched row and read the entries. Can someone suggest me how to do this? Regards, R.S
-
Hi All, I have 600 rows entries in a SQL database column "Name". At present I am looping through each row and searching for a text which should match the entries in "Name" column. My code is like this: For Each dr As DataRow In myDataSet.Tables(0).Rows If Trim(dr(("Name"))) = Trim(search_text) Then ' matching found... End If Next above, myDataSet contains the "Name" column data. Now, the above code is very time consuming, because it has to loop entire 600 times... What I am looking is any simple method, by which it direct jumps into the matched row and read the entries. Can someone suggest me how to do this? Regards, R.S
have a look at these dataview examples
-
Hi All, I have 600 rows entries in a SQL database column "Name". At present I am looping through each row and searching for a text which should match the entries in "Name" column. My code is like this: For Each dr As DataRow In myDataSet.Tables(0).Rows If Trim(dr(("Name"))) = Trim(search_text) Then ' matching found... End If Next above, myDataSet contains the "Name" column data. Now, the above code is very time consuming, because it has to loop entire 600 times... What I am looking is any simple method, by which it direct jumps into the matched row and read the entries. Can someone suggest me how to do this? Regards, R.S
Ever heard of the SQL 'LIKE' clause ?
-
Hi All, I have 600 rows entries in a SQL database column "Name". At present I am looping through each row and searching for a text which should match the entries in "Name" column. My code is like this: For Each dr As DataRow In myDataSet.Tables(0).Rows If Trim(dr(("Name"))) = Trim(search_text) Then ' matching found... End If Next above, myDataSet contains the "Name" column data. Now, the above code is very time consuming, because it has to loop entire 600 times... What I am looking is any simple method, by which it direct jumps into the matched row and read the entries. Can someone suggest me how to do this? Regards, R.S
The DataTable object has a .Select in which you can specify what would a WHERE portion of SQL and it will return an array of DataRows. This way you can pull a lot of data from a database just once, then filter it different ways quickly when you get it back. For your code above it would work something like this:
For Each row As DataRow In myDataSet.Tables(0).Select("Name='" & search\_text & "'") 'Perform your matching found task Next