public int Delete(Role Role_Code, Trans trans) { DBHelper db = new DBHelper(); DbCommand cmd = db.GetSqlStringCommand("DELETE FROM Role WHERE Role_Code = '" + Role_Code.Role_Code+"'"); return db.ExecuteNonQuery(cmd, trans); }
public int Update(Role Role, Trans trans) { DBHelper db = new DBHelper(); DbCommand cmd = db.GetStoredProcCommand("p_Role_update"); db.AddInParameter(cmd, "@Role_Code", DbType.Guid, Role.Role_Code); db.AddInParameter(cmd, "@Role_Name", DbType.String, Role.Role_Name); db.AddInParameter(cmd, "@DES", DbType.String, Role.DES); return db.ExecuteNonQuery(cmd, trans); }
public int Save(Role Role, Trans trans) { DBHelper db = new DBHelper(); DbCommand cmd = db.GetStoredProcCommand("p_Role_insert");//返回主键 db.AddInParameter(cmd, "@Role_Name", DbType.String, Role.Role_Name); db.AddInParameter(cmd, "@DES", DbType.String, Role.DES); object res = db.ExecuteScalar(cmd, trans); return res == null ? -1 : 1; }
/// <summary> /// 执行sql或者存储过程返回一个object对象+事务 /// </summary> /// <param name="cmd">cmd对象</param> /// <param name="t">事务执行操作</param> /// <returns></returns> public object ExecuteScalar(DbCommand cmd, Trans t) { cmd.Connection.Close(); cmd.Connection = t.DbConnection; cmd.Transaction = t.DbTrans; object ret = cmd.ExecuteScalar(); return ret; }
/// <summary> /// 执行一条sql语句或者存储过程,返回受影响的行数+事务 /// </summary> /// <param name="cmd">cmd对象</param> /// <param name="t">事务执行操作</param> /// <returns></returns> public int ExecuteNonQuery(DbCommand cmd, Trans t) { cmd.Connection.Close(); cmd.Connection = t.DbConnection; cmd.Transaction = t.DbTrans; int ret = cmd.ExecuteNonQuery(); return ret; }
/// <summary> /// 执行sql或者存储过程返回一个DbDataReader对象+事务 /// </summary> /// <param name="cmd">cmd对象</param> /// <param name="t">事务执行操作</param> /// <returns></returns> public DbDataReader ExecuteReader(DbCommand cmd, Trans t) { cmd.Connection.Close(); cmd.Connection = t.DbConnection; cmd.Transaction = t.DbTrans; DbDataReader reader = cmd.ExecuteReader(); DataTable dt = new DataTable(); return reader; }
/// <summary> /// 执行sql或者存储过程返回一个DataTable对象+事务 /// </summary> /// <param name="cmd">cmd对象</param> /// <param name="t">事务执行操作</param> /// <returns></returns> public DataTable ExecuteDataTable(DbCommand cmd, Trans t) { cmd.Connection = t.DbConnection; cmd.Transaction = t.DbTrans; DbProviderFactory dbfactory = DbProviderFactories.GetFactory(DBHelper.dbProviderName); DbDataAdapter dbDataAdapter = dbfactory.CreateDataAdapter(); dbDataAdapter.SelectCommand = cmd; DataTable dataTable = new DataTable(); dbDataAdapter.Fill(dataTable); return dataTable; }