plan_exestring = " if exists( select id from A where id = 3" +
" begin" +
" update A set 数量 = 数量 +" + 10 + " where id = 3" +
" end "+
" else"+
" begin"+
" insert into A(id,数量) values(3 ,10)"+
" end"; exec_SQL_using(plan_exestring)
private void exec_SQL_using(string GetString)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand(GetString, connection);
connection.Open();
cmd.ExecuteNonQuery();
}
}
这样一执行总说 begin end else begin end 附近有语法错误 !!!! 请教这怎样解决???????????
" begin" +
" update A set 数量 = 数量 +" + 10 + " where id = 3" +
" end "+
" else"+
" begin"+
" insert into A(id,数量) values(3 ,10)"+
" end"; exec_SQL_using(plan_exestring)
private void exec_SQL_using(string GetString)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand(GetString, connection);
connection.Open();
cmd.ExecuteNonQuery();
}
}