if (cznr.Text.Trim() != "")
        {
            cznrsql += " and   (isnull(a.usr,'') like '%" + cznr.Text.Trim() + "%')  ";
        }
        if (rbv != "2")
        {
            cznrsql += " and  (c.gs = " + rbv + " )  ";
        }
        string sql = "SELECT count(*) as rcount  FROM smsusr a left join smsusr_group c on a.groupid = c.id" + cznrsql;
System.Data.SqlClient.SqlException: 第 1 行: '=' 附近有语法错误。

解决方案 »

  1.   

    极有可能是rbv传进去值不对或为空,设个断点跟踪一下rbv的值
      

  2.   

    string rbv = RadioButtonList1.SelectedValue.ToString();
            string cznrsql = "where  ( 1=1 ) ";
            if (cznr.Text.Trim() != "")
            {
                cznrsql += " and   (isnull(a.usr,'') like '%" + cznr.Text.Trim() + "%')  ";
            }
            if (rbv != "2")
            {
                cznrsql += " and  (c.gs = " + rbv + " )  ";
            }
            string sql = "SELECT count(*) as rcount  FROM smsusr a left join smsusr_group c on a.groupid = c.id" + cznrsql;
      

  3.   

    你通过调试跟踪出来一个SQL语句拿到查询分析器中执行看看是否还是有错
      

  4.   

    能把SQL语句输出来么。Response.Write(sql);
      

  5.   

    是不是你 rbv 的类型有问题,试试加上 ' '
      

  6.   

    楼主你没有where啊,当然会报错
      

  7.   

    断点设置在
            string sql = "SELECT count(*) as rcount  FROM smsusr a left join smsusr_group c on a.groupid = c.id" + cznrsql;
    在局部变量窗口看看 sql 的值是什么。copy出来到查询分析器去执行一下。看看对不对还有
      if (rbv != "2")
    可能是null
    改为  if (rbv != "2" && rbv!=null)
      

  8.   

    或许是你的=号是中文输入,也许是sqlcommand或者SqldataAdapter里面参数不小心写错了,
    我今天就遇到了后面这个错误.
      

  9.   

    string sql = "SELECT count(*) as rcount  FROM smsusr a left join smsusr_group c on a.groupid = c.id" 后面要多加个空格,要不然跟Where就连起来了,变成
    c.idwhere...
      

  10.   

    rbv如果为空了?
    你看看rbv是否为空
      

  11.   

    把这行
    cznrsql += " and (c.gs = " + rbv + " ) ";
    改为:cznrsql += " and (c.gs = '" + rbv + "' ) ";
      

  12.   

    " + rbv + " 改成 "& rbv  &" ,int型的用"+ +"可能会有问题
      

  13.   

    Trim()   后面加上ToStirng()