我写了一个SQL语句 "select * from seachSql where sqlN='"+变量+"'"  结果运行说: 第 1 行: '10' 附近有语法错误。 看了网上有人说 改成"select * from seachSql where sqlN=@Description" 然后定义@Description  不知道@Description 是如何定义的 ? 还有就是为什么说 “第 1 行: '10' 附近有语法错误”?

解决方案 »

  1.   

    改成这样试试
    "select * from seachSql where sqlN='"&变量&"'"
    假如字段sqlN是int这样的类型的话,改成
    "select * from seachSql where sqlN="&变量不知道@Description 是如何定义的 ?这是要在存储过程里定义的。
      

  2.   

    一般是这样定义:
    declare @Description varchar(20)
      

  3.   

    sqlN 是 Text 类型的 ,tigerwen01(小虎)(编程艺术化) 
    declare @Description varchar(20)如楼上所说
    怎么把变量给@Description它,我还是不太明白 请解释 谢谢
      

  4.   

    这句"select * from seachSql where sqlN='"+变量+"'"
    如果变量在这里是int型或是string型的话是没有错的
    但若变量是string的话写成"select * from seachSql where sqlN="+变量
    就会出现你所说的错误,想必那变量里有0吧?
    所以你所说的应该是没有错的,你再检查几遍
      

  5.   

    sqlN 为数字型
    "select * from seachSql where sqlN="+变量+"" sqlN 为字符型
    "select * from seachSql where sqlN='"+变量+"'"
      

  6.   

    各位老大 我知道select怎么用,从语法上找不到问题,如果把 where sqlN='"+变量+"'"去掉,就运行正常,如果把改成where sqlN="&变量 就出现    “select”附近有错误  ,不知道为什么?郁闷
      

  7.   

    给个例子你看@Description 的用法 就是将值先赋给参数
    string SQL="Select * from admin where admin_name=@admin_name and admin_psw=@password";
    SqlCommand Cmd=new SqlCommand(SQL,Conn);
    Cmd.Parameters.Add(new SqlParameter("@admin_name",SqlDbType.VarChar));
    Cmd.Parameters.Add(new SqlParameter("@password",SqlDbType.VarChar));
    Cmd.Parameters["@admin_name"].Value =admin_name.Text.ToString();
    Cmd.Parameters["@password"].Value =password.Text.ToString();
    Conn.Open();
    SqlDataReader reader = Cmd.ExecuteReader();
      

  8.   

    简单的说:
    就是where后面可以跟两种形式的值
    一种是具体的值,
    假如你SqlN=15,你直接写15就对了,另外你通过
    declare @SqlN varchar(20)
    set @SqlN=多少,
    然后在你的where后跟上这个声明的参变量就可以了.至少你的那种写法.偶没有用过.
    上面两种仅供参考