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 附近有语法错误 !!!! 请教这怎样解决???????????

解决方案 »

  1.   

      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();
                }
            }
      

  2.   

    你看一下SQL语句就知道少啥了
      

  3.   

    可以跟下 plan_exestring的值,然后看那里出错了。