problem with making query wich contains parameter

I'm trying to make a program to manage my moviedatabase a little more user friendly.
Now i'm trying to add a new query to the adapter with the paramater.
But every time i do this i get this error saying error in WHERE clause near '@'.
Cannot parse query text.

This is my query:
SELECT ID, MapPos, Naam, Soort, Kwaliteit, Genre FROM Films where Naam = @naam

It adds the method but without the parameter.

Can anyone please help me, or say what i must do exactly :/

Thanx in advance


Answer this question

problem with making query wich contains parameter

  • ttme

    Thanx anyways ahmedilyas
    Very good to have people like you here

    one other question though , a bit more sql oriented but still..
    if i want to use the like statement, how can i do that

    SELECT ID, MapPos, Naam, Soort, Kwaliteit, Genre FROM Films where Naam like %@naam%

    this doesn't look right though , think it's more something like option deux

    another idea would be something like..

    StringBuilder sb = new StringBuilder();

    sb.Append = "%";

    sb.Append = txtZoek.Text;

    sb.Append = "%";

    filmsTableAdapter.FillByNaam(

    collectionDataSet.Films, sb);

    Then leave the % away in the query. This doesn't work, some problem.

    this gives me an error, thanx in advance

    ps: you can see i'm still very new to this


  • pjam

    thank you for the really fast response.
    Well i think i have to do some more reading. I was actually following this book with the example and everything. But they forgot to tell me anything about this.

    I just went to desing dataset, right mouse clicked the adapter and added a new query with the where and the parameter.

    Thinking it would be a lot easier using the GUI wizards.

    Btw this is the code i placed in the click event op my search button
    filmsTableAdapter.FillByNaam(
    collectionDataSet.Films, txtZoek.Text);

    here i get this error:
    Error 1 No overload for method 'FillByNaam' takes '2' arguments


  • Bill Charley

    basically you need to add a SqlParameter (or Oledb...you actually haven't specified the type of client you are using, Sql or Oledb )

    So...something like this:

    SqlCommand theSQLCommand = new SqlCommand("SELECT [ID], MapPos, Naam, Soort, Kwaliteit, Genre FROM Films WHERE Naam = @naam", theSqlConnection);

    SqlParameter theNaamParameter = new SqlParameter("@naam", SqlDbType.nvarchar, 50);

    theNaamParameter.Value = ValueHere;

    theSQLCommand.Parameters.Add(theNaamParameter);

    //then open connection and execute query

    does this help/give you some guidence you need to add a parameter to the collection of parameters in the SqlCommand (or OleDbCommand, making sure you use the right client and the right data types etc...) so when executing it, it can take the parameters it requires and do the search based on the parameter values



  • Alex Levin

    Great, glad you got it working, I was in the middle of replying when you posted :-)

  • Clarke76

    ok so i fixed the problem
    i just had to add a parameter in the properties op the method
    works like a charm now

  • problem with making query wich contains parameter