Results 1 to 2 of 2

Thread: Query Problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Posts
    66

    Query Problem

    I'm trying to use Like, but don't know how to do it. This is my code:

    searchAdapter = New OleDb.OleDbDataAdapter("Select * From ClientSystem WHERE Company_Name LIKE *@search*", connStr)
    searchAdapter.SelectCommand.Parameters.AddWithValue("@search", txtSearch.Text)


    May I ask also if this is possible, im creating a search button, need to check if the entered keyword is the Company_Name or Contact_Last_Name..

    searchAdapter = New OleDb.OleDbDataAdapter("Select * From ClientSystem WHERE Company_Name OR Contact_Last_Name LIKE *@search*", connStr)
    searchAdapter.SelectCommand.Parameters.AddWithValue("@search", txtSearch.Text)

    Kindly help me to correct this problem.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Query Problem

    For the first part, add the wildcards (which may need to be % or *) to the parameter rather than the SQL statement, eg:
    Code:
    searchAdapter = New OleDb.OleDbDataAdapter("Select * From ClientSystem WHERE Company_Name LIKE @search", connStr)
            searchAdapter.SelectCommand.Parameters.AddWithValue("@search", "*" & txtSearch.Text & "*")

    For comparing a value to two fields, you need to write out the condition twice - and if apt (like in this case) also add extra parameters.

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