public void del(string m)
{

SqlConnection conn1=new SqlConnection();
conn1.ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["aa"] ; string sql1="delete table aa where id="+m;
SqlCommand cmd1=new SqlCommand(sql1,conn1);

cmd1.CommandType=CommandType.Text;
cmd1.Connection.Open();
cmd1.ExecuteNonQuery();
conn1.Close();
}
我直接给m赋值的时候可以执行,但是我通过变量的时候就提示cmd1.ExecuteNonQuery(); 有错误
请帮我看一下是为什么呢?谢谢

解决方案 »

  1.   

    string sql1="delete table aa where id="+m;
    改为string sql1="delete table aa where [id]= '"+m + "'";
      

  2.   

    string sql1="delete table aa where id="+m;
    string sql1="delete table aa where id='"+m+"'";
      

  3.   

    这样可以?
    string sql1="delete table aa where id="+"1";
    这样不行?
    string sql1="delete table aa where id="+m;8可能的,你确定public void del(string m)传近来的参数是数字?
      

  4.   

    可以了?你的id字段是nvarchar类型?
      

  5.   


     
       string sql1="delete table aa where id="+m;
    string sql1="delete table aa where id='"+m+"'";
      
     
      

  6.   

    ID如果是INT型
    原来的也没错啊
    ID是什么型?
      

  7.   

    我的id是int类型的,但是写成string sql1="delete table aa where id="+m; 就是提示我cmd1.ExecuteNonQuery();有错误,当我改为string sql1="delete table aa where id='"+m+"'";的时候就可以了,我也一直纳闷呢!