MySqlCommand参数不起作用

Pro*_*ofK 3 .net mysql

在下面的代码中,用于获取特定行中的产品列表,该命令仅在我硬编码(连接)productLine到SQL 时返回结果.参数替换永远不会发生.

            + "lineName = '@productLine' "                       
            + "and isVisible = 1 ";
        MySqlDataAdapter adap = new MySqlDataAdapter(sql, msc);
        adap.SelectCommand.Parameters.Add("@productLine", productLine);
Run Code Online (Sandbox Code Playgroud)

Ome*_*ten 7

        + "lineName = ?productLine "                       
        + "and isVisible = 1 ";
    MySqlDataAdapter adap = new MySqlDataAdapter(sql, msc);
    adap.SelectCommand.Parameters.Add("?productLine", productLine);
Run Code Online (Sandbox Code Playgroud)
  1. 删除撇号(').
  2. 将@更改为?,这是MySql查询中参数的前缀.