Results 1 to 3 of 3

Thread: Problem with SLQ-SelectCommand with a wildcard (%)

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    1

    Question Problem with SLQ-SelectCommand with a wildcard (%)

    Hi all,

    I made a dataform1 (with the wizard) wich creates a OleDbDataAdapter1 and a objDataSet1. I made a second OleDbDataAdapter 2 and a DataSet2 for another quiery (on the same dataform) and afterwards i put in the following code:


    VB Code:
    1. PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim Zoekwoord As String
    3.         Zoekwoord = "%" & TextBox1.Text & "%"
    4.         OleDbDataAdapter2.SelectCommand.Parameters("NmEnVn").Value = Zoekwoord
    5.  
    6.         DataSet2.Clear()
    7.         OleDbDataAdapter2.Fill(DataSet2)
    8.  
    9. End Sub


    The OleDbDataAdapter2 has the select-command: SELECT NmEnVn, ID FROM Lijst WHERE (NmEnVn = ?)

    I put in a datagrid to verifie the result. With the code above, i don't get a result but not an error either.

    When I change:
    VB Code:
    1. Zoekwoord = "%" & TextBox1.Text & "%"
    in
    VB Code:
    1. Zoekwoord = TextBox1.Text

    I get a result when TextBox1.Text is exactly one of the names in "NmEnVn". But what I want is that if I type "Co" I will get all the results with "Co" in it, like "Cornelis" and "Coppens" and "Cosemans" ...

    Can someone help me pls? Can it be the problem that i'm working in a dataform ?

  2. #2
    Lively Member
    Join Date
    Jun 2004
    Posts
    99

    Re: Problem with SLQ-SelectCommand with a wildcard (%)

    Try changing your where clause to a LIKE.

    SELECT NmEnVn, ID FROM Lijst WHERE (NmEnVn LIKE '?')

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Problem with SLQ-SelectCommand with a wildcard (%)

    Quote Originally Posted by thecow95
    Try changing your where clause to a LIKE.

    SELECT NmEnVn, ID FROM Lijst WHERE (NmEnVn LIKE '?')
    The like bit is correct, but you don't want the single quotes or the "?" character will be treated as a literal instead of a place-holder:
    Code:
    SELECT NmEnVn, ID FROM Lijst WHERE NmEnVn LIKE ?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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