/// <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; }