Reputation: 51064
In the following code, used to get a list of products in a particular line, the command only returns results when I hard code (concatenate) productLine
into the SQL. The parameter substitution never happens.
+ "lineName = '@productLine' "
+ "and isVisible = 1 ";
MySqlDataAdapter adap = new MySqlDataAdapter(sql, msc);
adap.SelectCommand.Parameters.Add("@productLine", productLine);
Upvotes: 3
Views: 3046
Reputation: 11980
+ "lineName = ?productLine "
+ "and isVisible = 1 ";
MySqlDataAdapter adap = new MySqlDataAdapter(sql, msc);
adap.SelectCommand.Parameters.Add("?productLine", productLine);
Upvotes: 7
Reputation: 1845
That's correct it never happens you have
try
Upvotes: 0
Reputation: 30234
like he said
+ "lineName = '@productLine' "
should be
+ "lineName = @productLine "
Upvotes: 0
Reputation: 36310
Remove the apostrophes (spelling?). The ' around the parameter. They should not be needed.
Upvotes: 2