Results 1 to 3 of 3

Thread: Parameter Query with Wildcard, Access db

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2003
    Location
    North Carolina
    Posts
    2

    Question Parameter Query with Wildcard, Access db

    Hi, this is my first post. Thanks in advance for your help!

    I am connecting to an Access database, and I am successful in using a parameter query that selects with the value in a text box, if the value is an exact match for the value in the database. The problem is that I need to be able to use a wildcard. I am able to do this with a SQL database. I am confident that my connection objects and datasets are OK so I am not posting them here.

    'SQL, with wildcard (This works) (The user doesn't enter the wildcard)

    'SqlSelectCommand1

    Me.SqlSelectCommand1.CommandText = "SELECT CPT4Code, Description, IDCode FROM CPT4Codes WHERE (CPT4Code LIKE @codematch)"
    Me.SqlSelectCommand1.Connection = Me.SqlConnection1
    Me.SqlSelectCommand1.Parameters.Add(NewSystem.Data.SqlClient.SqlParameter("@codematch", System.Data.SqlDbType.NVarChar, 8, "CPT4Code"))

    CodeEntry = txtCodeEntry.Text
    Codem = CodeEntry & "%"
    SqlDataAdapter1.SelectCommand.Parameters("@codematch").Value = Codem
    SqlDataAdapter1.Fill(DataSet11)

    'Access Without Wildcard (This works)

    'OleDbSelectCommand1
    '
    Me.OleDbSelectCommand1.CommandText = "SELECT IDCode, CPT4Code, Description FROM CPT4Codes WHERE (CPT4Code = ?) ORDER BY" & _
    " CPT4Code"
    Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1
    Me.OleDbSelectCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("CPT4Code", System.Data.OleDb.OleDbType.VarWChar, 8, "CPT4Code"))

    CodeEntry = txtCodeEntry.Text
    OleDbDataAdapter1.SelectCommand.Parameters("CPT4Code").Value = CodeEntry
    OleDbDataAdapter1.Fill(DataSet21)

    'Access with wildcard
    'I have tried each of these without success:

    Codem = CodeEntry & "*"
    OleDbDataAdapter1.SelectCommand.Parameters("CPT4Code").Value = Codem
    OleDbDataAdapter1.Fill(DataSet21)

    Codem = CodeEntry & "%"
    OleDbDataAdapter1.SelectCommand.Parameters("CPT4Code").Value = Codem
    OleDbDataAdapter1.Fill(DataSet21)

  2. #2
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313
    The only issue I can see with the Access code is that you are using = instead of LIKE.
    Is that a posting typo, or is it perhaps your problem?

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2003
    Location
    North Carolina
    Posts
    2

    Thumbs up

    That was my mistake!
    It does work when I replace = with LIKE
    I thought I had tried LIKE. I probably ruled it out when it didn't work...but looking back, I guess I had something else wrong then.
    Thank You!

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