我想批量修改一组数据 然后这个修改的值是变量从textbox.text取得的,string a=textbox.text;
sqlcommand aacommand=thisconnection.createcommamd();
aacommand.commandText="update info set"+ "name="+ a + " where supplierid ="+id;
int num=aacommand.executenonquery();
其中 aacommand.commandtext 这样写对吗?

解决方案 »

  1.   

    SqlConnection connection = new SqlConnection(connString);
    string sql="update info set"+ "name="+ a + " where supplierid ="+id;
    SqlCommand cmd = new SqlCommand(sql, connection);
      

  2.   

    sqlcommand用法http://msdn.microsoft.com/zh-cn/library/system.data.sqlclient.sqlcommand(VS.80).aspx
      

  3.   

    其中a  id是什么类型的变量啊?字符型还是整型或者其他啊?你的name和supplierid又是什么类型的
    只要类型对,这样写就可以的
    string sql="update info set name="+ a.tostring()+ " where supplierid ="+id.toint32(); 
      

  4.   

    "update info set"+ "name="+ a + " where supplierid ="+id; 
    其中 a和 id最好用参数@name ,@id 不如很容易被sql注入的!http://www.mybuffet.cn
      

  5.   


    string a=textbox.text; 
    sqlcommand aacommand=thisconnection.createcommamd(); 
    aacommand.commandText="update info set name='"+ a.Replace("'","''") + "' where supplierid = "+id; 
    int num=aacommand.executenonquery();