在以下code,用于获取在特定的产品线列表,只返回命令结果的时候我很难code(连击) PRODUCTLINE
到SQL。参数替换从未发生过。
+lineName ='@productLine'
+和ISVISIBLE = 1;
MySqlDataAdapter的ADAP =新MySqlDataAdapter的(SQL,MSC);
adap.SelectCommand.Parameters.Add(@ PRODUCTLINE,PRODUCTLINE);
解决方案
+lineName =?PRODUCTLINE
+和ISVISIBLE = 1;
MySqlDataAdapter的ADAP =新MySqlDataAdapter的(SQL,MSC);
adap.SelectCommand.Parameters.Add(PRODUCTLINE?,PRODUCTLINE);
取出单引号(') 更改@来?,这是参数MySQL查询中的preFIX。
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);
解决方案
+ "lineName = ?productLine "
+ "and isVisible = 1 ";
MySqlDataAdapter adap = new MySqlDataAdapter(sql, msc);
adap.SelectCommand.Parameters.Add("?productLine", productLine);
Remove the apostrophes ('). Change @ to ?, which is the prefix of parameters in MySql queries.