第 1 行: 'select id from xh_main where id = 2' 附近有语法错误。
看看这句哪错了

解决方案 »

  1.   


    select id from xh_main where id = 2我晕,这句话,你都知道id=2了你还查它干啥
      

  2.   

    select id from xh_main where id = 2这句语法没问题,请检查一下其它地方或语句中是否存在全角空格
      

  3.   


    select [id] from xh_main where [id] = 2
      

  4.   

    在 sql += "id = "+id1+"";处设置一个断点看看,sql的值是什么。
      

  5.   

    或者是不是数据类型的问题?
    select id from xh_main where id = '2'
    或者select id from xh_main where cast(id as int)= 2
      

  6.   

    好好学习吧虽然不懂但是一看就知道有问题
    tbmyclass.admin_chaxun()这函数根本就没有参数 你给他传什么参数啊?
    这样试试:
    tbmyclass.admin_chaxun(string sqlstr)//方法:
    {
      SqlConnection conn = myconn();
      conn.Open();
      SqlDataAdapter sda = new SqlDataAdapter(sqlstr,conn);
      DataTable dt = new DataTable();
      sda.Fill(dt);
      conn.Close();
      conn.Dispose();
      return dt;   
        
      }
      

  7.   

    首先,传参数给admin_chaxun()这个方法了。
    其次,我看了sql值是"select id from xh_main where id = 2",应该是对的
      

  8.   

    我前面少复制了一行,下面这个是方法 
    public DataTable admin_chaxun(string sqlstr)   //根据条件查询返回结果
           {
               SqlConnection conn = myconn();
               conn.Open();
               SqlDataAdapter sda = new SqlDataAdapter("'" + sqlstr + "'",conn);
               DataTable dt = new DataTable();
               sda.Fill(dt);
               conn.Close();
               conn.Dispose();
               return dt;                 
           
           
           }