CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 27 of 27
  1. #16
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: PLs pls help me!!!!!!!!!

    That's not the propblem. If you look at the following code segment
    Code:
           With rs2
               .Open strSQL, conn1, adOpenStatic, adLockOptimistic
               Set MSHFlexGrid1.DataSource = rs2
               If .EOF ...
    you'd note that immediately after the rs2.Open statement I have connected the flexgrid to the datasource of rs2. The result of the Open statement should immediately show in the grid.
    At the time of open the sql line is
    Select * from personaldetails where Student_name like "c*";
    and the results are zero
    Change the sql to
    Select * from personaldetails where Student_name like "chris";
    and it finds the record where Student_name is chris.
    So why does the Like "c*" not find chris, too? That's here the question.

    I'd anyway advise more changes to the code belonging the .EOF, but this makes no sense as long as the Like statement does not deliver records as expected.

  2. #17
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: PLs pls help me!!!!!!!!!

    Ok, I seem to have bumped into the solution. It is the "*" operator.
    I don't know why, but if you look for the syntax of the Like operator in SQL statements you'll find two different descriptions, one denoting the "*" character as wildcard, the other one wants the "%" in this place. For some reason (maybe depending on the version of Access database) in your studentdetails.mdb the "%" sign works as a wildcard.

    I have stripped down your code from redundant repetitions you did in the Case clauses to show you how the function you want is easily accomplished.
    Just put this code into Text1_Change():
    Code:
    Private Sub Text1_Change()
      conndb
    
      Set rs2 = New ADODB.Recordset
      Dim strSQL As String, sqlquery As String
      
      sqlquery = "Select * from personaldetails"
      
      Select Case Combo1.Text
        Case Is = "Name"
             sele = 1
             MSHFlexGrid1.LeftCol = 1
             strSQL = sqlquery & " where Student_name like """ & Trim(Text1.Text) & "%"";"
    
        Case Is = "ID No"
             sele = 2
             MSHFlexGrid1.LeftCol = 0
             strSQL = sqlquery & " where ID like '*" & Trim(Text1.Text) & "*'"
      
        Case Is = "Last Name"
             sele = 3
             MSHFlexGrid1.LeftCol = 2
             strSQL = sqlquery & " where Last_name like '" & Trim(Text1.Text) & "*'"
      End Select
      
      With rs2
          .Open strSQL, conn1, adOpenStatic, adLockOptimistic
          Set MSHFlexGrid1.DataSource = rs2
          If .EOF Then
             MsgBox "The Search Criteria Have Been Complete." & vbCrLf & "Or Result Not Found In Database!!", vbExclamation, "Search Error Failed."
             SendKeys "{Home}+{End}"
             'On Error Resume Next
          End If
      End With
      'MSHFlexGrid1.Refresh
      Label2.Visible = True
    End Sub
    You'll note that the Select Case is only used to determine the SQL string (using "%" as wildcard) and then the database is accessed. You need not repeat this code three times, too.
    Also the complete ELSE clause of the If .EOF seemed useless, yet even wrong, so I left it away.
    I think this is what you attempted and I'm sure you can now go on with it.

  3. #18
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: PLs pls help me!!!!!!!!!

    And please also note how easy it is to read and understand code if you keep indendation logically structured.

  4. #19
    Join Date
    Jan 2010
    Posts
    12

    Talking Re: PLs pls help me!!!!!!!!!

    wow i didnt see ya last post sorry!!!
    u r genius.........
    it works thnks bro!!!!!!!!!!!!!!!!!!
    u were right ill surly follow ur instructions....................

  5. #20
    Join Date
    Jan 2010
    Posts
    12

    Re: PLs pls help me!!!!!!!!!

    thnks a lot.u saved me..
    can i consult ya if there are any further probs???

  6. #21
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: PLs pls help me!!!!!!!!!

    Quote Originally Posted by WoF View Post
    And please also note how easy it is to read and understand code if you keep indendation logically structured.
    I noticed that I had to use & to get a phone number to work with LIKE, but names worked with *
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #22
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: PLs pls help me!!!!!!!!!

    @analyse300: Sure feel free to come back any time.

    @David:
    What intrigues me is the two different explanations.
    The Like statement in VB works with the "*" as a wildcard, sure. That's in the manual.

    But then you lookup the SQL Like statement and find two different explanations.
    One says "*" is the wildcard, the other says "%" is the wildcard.
    After my testing with the database of the OP, most obviously the "%" is the wildcard.
    The "*" produces an emty recordset

    The starnge thing is, when opening that particular database with access and create an adequate query, you have to use "*" as a wildcard to produce a result.
    Doing the same thing via ADO.Recordset.Open method you HAVE TO use the "%". I tried to copy the query from Access (with the "*") and it didn't work. Changing * to % worked immediately.

    I'm a bit baffled about that one and have not yet worked out the reason for it. Are there different versions of SQL connected with the ADO library?

  8. #23
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: PLs pls help me!!!!!!!!!

    Might be different versions of the ADOC library. I learned the hard way a few years ago, thanks to pete (wonder where he went?)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  9. #24
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: PLs pls help me!!!!!!!!!

    Quote Originally Posted by dglienna View Post
    Might be different versions of the ADOC library. I learned the hard way a few years ago, thanks to pete (wonder where he went?)
    I have seen that in more modern languages like C# they always use '%' as a wildcard while when I was working with older versions of ADODB I always had to use '*' as wildcard. But thats simple my experience
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  10. #25
    Join Date
    Oct 2006
    Posts
    327

    Re: PLs pls help me!!!!!!!!!

    Hello,

    May I ? ===>>
    http://msdn.microsoft.com/en-us/libr...ice.10%29.aspx
    The "The ADO monkey wrench" paragraph is the one we have to read with more attention. Other wildcard characters changed, too...

  11. #26
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: PLs pls help me!!!!!!!!!

    OK. A bit older than ADO versions, it's the old DAO library in Access 97 (and VB6)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  12. #27
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: PLs pls help me!!!!!!!!!

    Well, this all sounds as if we would have to run a testroutine to determine which character is wild.
    If Select * from table where name like "*" returns no record, we have to try "%"?
    Interesting to hear about the ALike operator. Never heard before. And this one always uses "%"?

Page 2 of 2 FirstFirst 12

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