Results 1 to 8 of 8

Thread: SQL problem

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Location
    ottawa, canada
    Posts
    233

    SQL problem

    Hi All,

    I am using VB6 and connecting to my DB using DAO

    I am trying to create a search wherby a user would input say 3 letters in to a textbox and the resulting matches would populate a msflexgrid.

    For example, if he types in 'sic', then this would find 'basic force gauge' from the gauges table.

    I have used the code below and although i have used the Like command, the search brings up 0 records. Yet i know that there several matches to the query.

    Can you have a look at the query. I'm sure this is where the problem is, but not sure how to correct6

    Many Thanks



    strSQL = "Select Instrumentdescription, Instrumennumber From GAUGES where Instrumentdescription Like '" & Text1.Text & "'"
    Data1.RecordSource = strSQL
    Data1.Refresh
    Data1.UpdateControls

  2. #2
    Fanatic Member davebat's Avatar
    Join Date
    Dec 2002
    Posts
    727

    Re: SQL problem

    You have't added wildcards, try:

    Code:
    strSQL = "Select Instrumentdescription, Instrumennumber From GAUGES where Instrumentdescription Like '%" & Text1.Text & "%'"

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Location
    ottawa, canada
    Posts
    233

    Re: SQL problem

    Hi Davebat,

    That was my mistake. In my project i have got the wildcards. I quickly typed in the code here and ommited the wildcards by mistake.

    Even with the wildcards i get no results back.

  4. #4
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: SQL problem

    try this...
    vb Code:
    1. strSQL = "Select Instrumentdescription, Instrumennumber From GAUGES where Instrumentdescription Like '*" & Text1.Text & "*'"
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  5. #5
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: SQL problem

    What DB are you using? Different DBs use different wildcards. If it's access you want the * that Ganeshmoorthy suggested. For SQL Server you use %. Other DB's use different wild cards again but most use one of these two characters.

  6. #6
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: SQL problem

    All DB use the % sign for wildcards. Even Access if you are preforming the seach though ADO from VB.

    Please post the exact SQL string that is being passed from the application to the DB.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Location
    ottawa, canada
    Posts
    233

    Re: SQL problem

    Thanks Ganeshmoorthy,

    The code you suggested has fixed the problem.

    Many Thanks

  8. #8
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: SQL problem

    sparkash: You are most welcome and thanks for your rep points...
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


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