Error in Where clause near '@' (MySQL DB)

Last post 11-11-2009 3:47 PM by Bazanaka. 3 replies.

Sort Posts:

  • Error in Where clause near '@' (MySQL DB)

    11-07-2009, 5:40 AM
    • Member
      6 point Member
    • Bazanaka
    • Member since 11-05-2009, 4:07 PM
    • Posts 6

    Error in Where clause near '@' (MySQL DB)

     

    I want to configure a TableAdapter GetProductsByCategoryID(@CategoryID) method.

    I tried the following script: (I entered this in the TableAdapter wizard)

     

    SELECT *
    FROM Products
    WHERE CategoryID = @CategoryID

     

    The @CategoryID parameter shoud indicate to the TableAdapter wizard that the method I’m creating will require an input parameter of the corresponding type (namely, a nullable integer), but it keeps returning:

    Error in Where clause near '@'

    Unable to parse query text

     

    I'm using a MySQL ODBC 5.1 driver.

    Can anyone help?

  • Re: Error in Where clause near '@' (MySQL DB)

    11-07-2009, 6:52 AM
    • Member
      393 point Member
    • sanjeev87
    • Member since 09-22-2009, 12:39 PM
    • Bhubaneswar,Bangalore
    • Posts 75

    SqlCommand cmd=new SqlCommand("SELECT * FROM Products WHERE CategoryID = @CategoryID");
     

    i hope you have added this

    cmd.Parameters.Add("@CategoryID",SqlDbType.Int).Value=cid;

    where cid is your customerid

    please go through the article.

    http://forums.asp.net/t/886691.aspx


    It feels good when someone really appreciate your efforts.please mark as answer if it has helped you.This can be helpful for those who face the same problem in future.
  • Re: Error in Where clause near '@' (MySQL DB)

    11-08-2009, 9:12 AM
    • Member
      6 point Member
    • Bazanaka
    • Member since 11-05-2009, 4:07 PM
    • Posts 6

    Thanks for you reply, but I think your code has to do with creating the query from the code.

    I am trying to create the query in the TableAdapter wizard.

    I did some more research and I think the problem has to do with my MySQL connection. It probably can't handle the @Category input parameter. Using MS SQL Server should probably work.

    I guess I need find out how to use the input parameter with MySQL..

  • Re: Error in Where clause near '@' (MySQL DB)

    11-11-2009, 3:47 PM
    Answer
    • Member
      6 point Member
    • Bazanaka
    • Member since 11-05-2009, 4:07 PM
    • Posts 6

    I got it to work.

    I created a new DB connection through the Server Explorer. I selected MySQL Database as datasource, instead of ODBC Data Source, which I used first. For the MySQL Datasource I opened the Advanced options. Here is a property "user arguments" that should be set to true. After that the input parameters work.

Page 1 of 1 (4 items)