SQL: Trying to obtain all rows that have a primary key inside a inputted table
The code works if the Recipe string replaces the ? in the string. However, as I want to prevent SQL injection the RecipeString isn't treated as SQL so the ' ' either side of each name in RecipeString isn't identified in the SQL string hence returning no values. Hopefully you understand the issue. If anyone has any ideas on how to fix this it would be greatly appriciated. Thanks
Code:
Example Recipe String is:
4 Replies
You should be using a parameterized query, ex: https://stackoverflow.com/questions/10898737/parameterize-sql-query
Stack Overflow
Parameterize SQL query
Many posts about Parameters in SQL with C# but I am still missing something. I am not getting an error message but no data is inserted. What is missing? I have text boxes named fname, lname, address,
Sorry I didn't explain it well, I am currently using parameters in all my sql requests (code for the ExectuteSqlQuery method below), the parameters code is all working however as I am including the ' ' either side of the recipe names inside the parameter, the SQL code doesn't recognise the ' ' which are needed for the SQL to recognise each individual recipe name, so the IN method doesn't work. (There are no error messages aswell)
This works
This doesn't
but the parameters do work in other SQL requests
may need to make a new parameter for each value you're passing in, should be easy to format your query to handle this
I tried making a new parameter for each value however that didn't seem to work due to the second scenario here
tried it again seemed to fix it
thanks