Using Like Operator While Searching

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vandanasridhar
    New Member
    • Mar 2007
    • 21

    Using Like Operator While Searching

    HELLO JI
    i wish to get records from file having name candidate_detai l. for this i use following coding.it never give me any error but can't show record available in file.

    i m sending the code as below:

    Private Sub Command3_Click( )
    Set rs = New adodb.Recordset
    rs.Open "Select * from Candidate_Detai l where Candidate_Name like ' " & (Text1) & " '", con, adOpenForwardOn ly, adLockOptimisti c

    If rs.EOF = True Then
    MsgBox "No Such Records"
    Else
    Text2 = rs.Fields(2)
    Text3 = rs.Fields(3)
    Text4 = rs.Fields(4)
    Text5 = rs.Fields(5)
    Text6 = rs.Fields(6)
    Text7 = rs.Fields(7)
    Text8 = rs.Fields(8)
    Text9 = rs.Fields(9)
    Text10 = rs.Fields(10)
    Text11 = rs.Fields(11)
    Text12 = rs.Fields(0)
    End If
    end sub
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    in sql for searching the syntax is

    [CODE=oracle]Select * from Candidate_Detai l where Candidate_Name like '%das%'[/CODE]

    modify your sql string accordingly.

    Comment

    • hariharanmca
      Top Contributor
      • Dec 2006
      • 1977

      #3
      Originally posted by vandanasridhar
      HELLO JI
      i wish to get records from file having name candidate_detai l. for this i use following coding.it never give me any error but can't show record available in file.

      i m sending the code as below:

      Private Sub Command3_Click( )
      Set rs = New adodb.Recordset
      rs.Open "Select * from Candidate_Detai l where Candidate_Name like ' " & (Text1) & " '", con, adOpenForwardOn ly, adLockOptimisti c

      If rs.EOF = True Then
      MsgBox "No Such Records"
      Else
      Text2 = rs.Fields(2)
      Text3 = rs.Fields(3)
      Text4 = rs.Fields(4)
      Text5 = rs.Fields(5)
      Text6 = rs.Fields(6)
      Text7 = rs.Fields(7)
      Text8 = rs.Fields(8)
      Text9 = rs.Fields(9)
      Text10 = rs.Fields(10)
      Text11 = rs.Fields(11)
      Text12 = rs.Fields(0)
      End If
      end sub

      Just check your query

      "Select * from Candidate_Detai l where Candidate_Name like ' " & (Text1) & " '",

      like '<Space>" & (Text1) & "<Space>'"

      so if you give 'vandanasridhar ' then it will look for '<Space>vandana sridhar<Space>'
      Just check that and why you are not using proper property for controles like

      Text1.Text is given as Text1

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        Originally posted by hariharanmca
        Just check your query
        "Select * from Candidate_Detai l where Candidate_Name like ' " & (Text1) & " '",
        like '<Space>" & (Text1) & "<Space>'"
        so if you give 'vandanasridhar ' then it will look for '<Space>vandana sridhar<Space>'
        Just check that and why you are not using proper property for controles like
        Text1.Text is given as Text1
        Where is the space in the sql part ?
        and TEXT is the default property of the TextBox control , so specify that property is totally optional.

        Comment

        • hariharanmca
          Top Contributor
          • Dec 2006
          • 1977

          #5
          Originally posted by debasisdas
          Where is the space in the sql part ?
          and TEXT is the default property of the TextBox control , so specify that property is totally optional.
          Just check the #1 Sql query

          "Select * from Candidate_Detai l where Candidate_Name like '<Space>" & (Text1) & "<Space>'",
          He is giving the space between single quote(') and double quotes(")

          yes text property is optional but that is not good Practice to write a bulky code.

          Comment

          • QVeen72
            Recognized Expert Top Contributor
            • Oct 2006
            • 1445

            #6
            Originally posted by vandanasridhar
            HELLO JI
            i wish to get records from file having name candidate_detai l. for this i use following coding.it never give me any error but can't show record available in file.

            i m sending the code as below:

            Private Sub Command3_Click( )
            Set rs = New adodb.Recordset
            rs.Open "Select * from Candidate_Detai l where Candidate_Name like ' " & (Text1) & " '", con, adOpenForwardOn ly, adLockOptimisti c

            If rs.EOF = True Then
            MsgBox "No Such Records"
            Else
            Text2 = rs.Fields(2)
            Text3 = rs.Fields(3)
            Text4 = rs.Fields(4)
            Text5 = rs.Fields(5)
            Text6 = rs.Fields(6)
            Text7 = rs.Fields(7)
            Text8 = rs.Fields(8)
            Text9 = rs.Fields(9)
            Text10 = rs.Fields(10)
            Text11 = rs.Fields(11)
            Text12 = rs.Fields(0)
            End If
            end sub
            Hi,

            if ur backend database is Access then:

            [code=vb]
            rs.Open "Select * from Candidate_Detai l where Candidate_Name like '*" & (Text1) & "*'", con, adOpenForwardOn ly, adLockOptimisti c

            [/code]

            Replace * with % if backend is Oracle or MS SQL


            REgards
            Veena

            Comment

            Working...