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

Thread: SQL Like in VB

  1. #1
    Join Date
    Nov 1999
    Posts
    4

    SQL Like in VB

    I have a form that I need to add the ability to search for mult parameters in a query by the end user. I am having trouble with running an SQL query from my app with the LIKE operator
    For instance:
    Query from three text boxes; txtFirm , txtFirstName, txtLastName
    Access database table called KDetail Using ADO control w/ Access 2000
    ---------------
    Private Sub cmdSearch_Click

    Dim aSQL as string '
    Dim A, B, C as String
    A= txtFirm
    B= txtFirstName
    C= txtLastName
    aSQL = "SELECT * FROM KDetail WHERE Firm Like '"&(A)&"' AND FirstName Like" & _
    " '"&(B)"' AND LastName Like '"&(C)"'"
    If adoKDetail.Recordset.RecordCount = 0 Then
    msgbox("No Record Found")
    End If
    End Sub
    -----------------

    When the code runs it doesn't allow for partial information ie Stev* for Steve
    I only get the msgbox "No Record Found"

    Bill






  2. #2
    Guest

    Re: SQL Like in VB

    First, speaking explicitly to make the routine 'clean' the lines:
    a=txtfirm
    b=txtfirstname
    c=txtlastname
    should be changed to:
    a=txtfirm.text
    b=txtfirstname.text
    c=txtlastname.text
    Second, as a test, search explicitly for "Stev*" as noted. It should allow it. Explicitly add the * in the SQL.


  3. #3
    Guest

    Re: SQL Like in VB

    Use %, do not use *
    This is feature of ADO !!!


  4. #4
    Join Date
    Nov 1999
    Posts
    4

    Re: SQL Like in VB

    It worked well....Thanks




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