public DataTable ExecuteDataTable(DbCommand cmd, Trans t) { cmd.Connection = t.DbConnection; cmd.Transaction = t.DbTrans; DbDataAdapter adapter = DbProviderFactories.GetFactory(_dbProviderName).CreateDataAdapter(); adapter.SelectCommand = cmd; DataTable dataTable = new DataTable(); adapter.Fill(dataTable); this._connection.Close(); return dataTable; }
protected void Page_Load(object sender, EventArgs e) { string sql = " update transtest set [name]='jhhhh2' where [id]=1 "; string sql2 = " update transtest set [name]='love2' where [id]=2 "; using (Trans t = new Trans()) { DbHelper dh = new DbHelper(); try { DbCommand cmd = dh.GetSqlStringCommond(sql); dh.ExecuteNonQuery(cmd, t); cmd = dh.GetSqlStringCommond(sql2); dh.ExecuteNonQuery(cmd, t); throw new Exception("hhhhh"); t.Commit(); } catch (Exception ee) { t.RollBack(); Response.Write(ee.Message); } } }
public object ExecuteScalar(DbCommand cmd, Trans t) { cmd.Connection.Close(); cmd.Connection = t.DbConnection; cmd.Transaction = t.DbTrans; object ret = cmd.ExecuteScalar(); return ret; }
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; }
public int ExecuteNonQuery(DbCommand cmd, Trans t) { cmd.Connection.Close(); cmd.Connection = t.DbConnection; cmd.Transaction = t.DbTrans; int ret = cmd.ExecuteNonQuery(); return ret; }
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; }
public int ExecuteSql(DbCommand cmd, Trans t) { cmd.Connection.Close(); cmd.Connection = t.DbConnection; cmd.Transaction = t.DbTrans; int num = cmd.ExecuteNonQuery(); this._connection.Close(); return num; }
public object ExecuteScalar(DbCommand cmd, Trans t) { cmd.Connection.Close(); cmd.Connection = t.DbConnection; cmd.Transaction = t.DbTrans; object obj2 = cmd.ExecuteScalar(); this._connection.Close(); return obj2; }