CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: search

  1. #1
    Join Date
    Aug 2001
    Location
    The Netherlands, near germany
    Posts
    42

    search

    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
    [email protected]

  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: search

    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
    [email protected]

    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
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    Aug 2001
    Location
    The Netherlands, near germany
    Posts
    42

    Re: search

    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
    [email protected]

  4. #4
    Join Date
    Aug 2001
    Location
    The Netherlands, near germany
    Posts
    42

    Re: search

    I'am working with data1, and what do you mean with cnn??

    Remco Ploeg
    [email protected]

  5. #5
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: search

    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
    [email protected]

    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
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured