的MySqlCommand参数不工作参数、工作、MySqlCommand

2023-09-05 03:00:40 作者:心劫

在以下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 autocommit 关于mysql 的 autoCommit 参数

取出单引号(') 更改@来?,这是参数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.