的MySqlCommand参数不工作 [英] MySqlCommand Parameter not Working

查看:179
本文介绍了的MySqlCommand参数不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下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);
 

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

  1. Remove the apostrophes (').
  2. Change @ to ?, which is the prefix of parameters in MySql queries.

这篇关于的MySqlCommand参数不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆