sql语句使用变量更新表

时间:2014-05-30 07:24:12

标签: sql

String sql1 = 
" UPDATE filename SET @count=@valu2 where @name12=@fname1 ";
stmt = connection_ms.con.createStatement();
stmt.executeUpdate(sql1);

此处valu2fname1是变量,它会给出错误

1 个答案:

答案 0 :(得分:0)

如下所示

sqlconnection con=new sqlconnection("your connection string");
string sql1 ="UPDATE filename SET @count=@valu2 where @name12=@fname1 ";
sqlcommand com=new sqlcommand(sql1,con);
com.parameters.addwithvalue("@valu2","enter valu2 here");
com.parameters.addwithvalue("@fname1 ","enter fname1  here");
con.open();
com.executenonquery();
con.close();