.NET批量更新

扶文光
2023-12-01
public bool BatchUpdate(int id, string reason)
        {
            using (SqlConnection connection = new SqlConnection(DbHelperSQL.connectionString))
            {
                connection.Open();
                SqlCommand command = connection.CreateCommand();
                SqlTransaction transaction = connection.BeginTransaction();
                command.Connection = connection;
                command.Transaction = transaction;
                try
                {
                    string sql = string.Empty;
                    if (!string.IsNullOrEmpty(reason))
                    {
                        sql = "update news set ispass=3,datecheck=getdate(),FailReason='" + reason + "' where id=" + id;
                    }
                    else
                    {
                        sql = "update news set ispass=2,datecheck=getdate() where id=" + id;
                    }
                    command.ExecuteNonQuery();
                    transaction.Commit();
                    return true;
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    return false;
                }
            }
        }

 

转载于:https://www.cnblogs.com/GreatPerson/p/7097372.html

 类似资料: