Click to See Complete Forum and Search --> : search


remcoploeg
August 27th, 2001, 04:52 AM
Hello, I want to search via vb6 in a mysql database and show the record. How can I do that.
So I want to search for the company: XYZ. I put that in a box and then search, if he found the record, he show it else he say no record found.
How can I do that.

thanks in advance

Remco Ploeg
ploegr@promar-agencies.nl

Cakkie
August 27th, 2001, 05:02 AM
This presumes that you are using ADO and are already connected to the database via an ADODB.Connection called cnn.

dim rst as ADODB.Recordset
set rst = cnn.execute("SELECT * FROM tblCompanies WHERE CompCode='XYZ'")

If rst.EOF anf rst.BOF then
Msgbox "Company not found!"
else
txtName.text = rst("CompName")
txtAdres.text = rst("CompAdres")
txtCity.text = rst("CompCity")
End IF




Tom Cannaerts
slisse@planetinternet.be

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook

remcoploeg
August 27th, 2001, 05:55 AM
I want to have a like statement. And then show all the record for example a%.Then search, then show all the record with a "A"

Remco Ploeg
ploegr@promar-agencies.nl

remcoploeg
August 27th, 2001, 06:06 AM
I'am working with data1, and what do you mean with cnn??

Remco Ploeg
ploegr@promar-agencies.nl

Cakkie
August 27th, 2001, 06:35 AM
If you are using Data1, you are probably using a datacontrol.
The datacontrol should exposes a object called recordset, this can be compared with the rst in the code i gave you. Only now, we can't do a select on the data, we will have to find it. We can do this using the filter property of the recordset.

Data1.Recordset.Filter = "CompName LIKE 'A%'"
If Data1.Recordset.EOF and Data1.Recordset.BOF then
MsgBox "No Records found"
else
Data1.Recordset.MoveFirst
End If



If you are sure you have records, but they aren't showing, try changing the % in a *.
Since you are using a datacontrol, I assume that tha data is bound to controls, and the filling of the fields is done automatically. If not, you can address a field in the recordset directly

txtName.Text = Data1.Recordset.Fields("CompName")




Tom Cannaerts
slisse@planetinternet.be

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook