SqlTransaction trans = null; SqlConnection con = new Sqlconnection("数据库链接语句"); try { con.Open(); trans = con.BeginTransaction(); SqlCommand com = new SqlCommand(); //一下4步是要执行SqlParameter,若是不执行能够直接跳过使用com.CommandText="SQL语句"; com.CommandText = @"数据库语句 条件=@变量"; SqlParameter para = new SqlParameter("变量","值"); com.Parameters.Add(para); com.CommandText=com.CommandText; com.Connection=con; com.Transaction=trans; com.ExecuteNonQuery();//执行方式本身选择 trans.Commit();//执行提交事务 }catch { trans.Rollback();//若是前面有异常则事务回滚 } finally { con.Close(); }