bluejaguar456 Posted January 7, 2009 Posted January 7, 2009 Hey Guys, I have beeen working on a program for my sisters company for some time now, but recently had a break from it. I am now back on track with it though finally! :) I am stuck on how to search the database for records containing a word the user specifies. At the moment i have got the code sql = "SELECT * FROM tblclient" & txtsurname.Text '' WILL NOT EARCH FOR SPECIFIED TEXT!!!! da = New OleDb.OleDbDataAdapter(sql, con) da.Fill(ds, "Eclypse Live") maxrows = ds.Tables("Eclypse Live").Rows.Count lbltotallresults.Text = maxrows & " clients found." inc = inc + 1 lnkresult1.Text = ds.Tables("Eclypse Live").Rows(inc).Item(1) & " " & ds.Tables("Eclypse Live").Rows(inc).Item(2) & " / " & ds.Tables("Eclypse Live").Rows(inc).Item(0) inc = inc + 1 lnkresult2.Text = ds.Tables("Eclypse Live").Rows(inc).Item(1) & " " & ds.Tables("Eclypse Live").Rows(inc).Item(2) & " / " & ds.Tables("Eclypse Live").Rows(inc).Item(0) inc = inc + 1 lnkresult3.Text = ds.Tables("Eclypse Live").Rows(inc).Item(1) & " " & ds.Tables("Eclypse Live").Rows(inc).Item(2) & " / " & ds.Tables("Eclypse Live").Rows(inc).Item(0) inc = inc + 1 lnkresult4.Text = ds.Tables("Eclypse Live").Rows(inc).Item(1) & " " & ds.Tables("Eclypse Live").Rows(inc).Item(2) & " / " & ds.Tables("Eclypse Live") This displays the records in labels that i want but only ggooes through the database without filtering the results of a search. I need to be able to search through the database for the surname of a person. This will be under item(1) and the search would be a string that the user enters... Can anyone help? The following is the code iss the SQL for getting all records from he database without filtering SELECT * FROM tblclient Quote
Nate Bross Posted January 7, 2009 Posted January 7, 2009 First, you'll want to look into Parameterizing your SQL (See also http://www.xtremedotnettalk.com/showthread.php?p=463520) The second thing, is that you'll need to use the SQL LIKE keyword: SELECT * FROM tblclient WHERE [FirstNameColumn] LIKE '%bob%'; Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
bluejaguar456 Posted January 8, 2009 Author Posted January 8, 2009 Thanks, i haave solved the problem now by using the statment you said, i ran into another problem bu jst for to update the dataset thanks a lot. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.