本文整理汇总了C#中System.Data.OleDb.OleDbTransaction类的典型用法代码示例。如果您正苦于以下问题:C# OleDbTransaction类的具体用法?C# OleDbTransaction怎么用?C# OleDbTransaction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OleDbTransaction类属于System.Data.OleDb命名空间,在下文中一共展示了OleDbTransaction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateAddProductCommand
public OleDbCommand CreateAddProductCommand(OleDbConnection conn, OleDbTransaction transaction)
{
var cmd = new OleDbCommand(ConvertToOleDbQuery(_sql), conn, transaction);
CreateParameters(cmd);
return cmd;
}
示例2: DeleteList
/// <summary>
/// ²éÕÒ²»´æÔÚµÄͼƬ²¢É¾³ýÒÑɾ³ýµÄͼƬ¼°Êý¾Ý
/// </summary>
public void DeleteList(OleDbConnection conn, OleDbTransaction trans, List<Model.article_albums> models, int article_id)
{
StringBuilder idList = new StringBuilder();
if (models != null)
{
foreach (Model.article_albums modelt in models)
{
if (modelt.id > 0)
{
idList.Append(modelt.id + ",");
}
}
}
string id_list = Utils.DelLastChar(idList.ToString(), ",");
StringBuilder strSql = new StringBuilder();
strSql.Append("select id,big_img,small_img from dt_article_albums where article_id=" + article_id);
if (!string.IsNullOrEmpty(id_list))
{
strSql.Append(" and id not in(" + id_list + ")");
}
DataSet ds = DbHelperOleDb.Query(conn, trans, strSql.ToString());
foreach (DataRow dr in ds.Tables[0].Rows)
{
int rows = DbHelperOleDb.ExecuteSql(conn, trans, "delete from dt_article_albums where id=" + dr["id"].ToString()); //ɾ³ýÊý¾Ý¿â
if (rows > 0)
{
Utils.DeleteFile(dr["big_img"].ToString()); //ɾ³ýÔͼ
Utils.DeleteFile(dr["small_img"].ToString()); //ɾ³ýËõÂÔͼ
}
}
}
示例3: DeleteList
/// <summary>
/// 查找不存在的图片并删除已删除的图片及数据
/// </summary>
public void DeleteList(OleDbConnection conn, OleDbTransaction trans, List<Model.article_albums> models, int article_id)
{
StringBuilder idList = new StringBuilder();
if (models != null)
{
foreach (Model.article_albums modelt in models)
{
if (modelt.id > 0)
{
idList.Append(modelt.id + ",");
}
}
}
string id_list = Utils.DelLastChar(idList.ToString(), ",");
StringBuilder strSql = new StringBuilder();
strSql.Append("select id,thumb_path,original_path from " + databaseprefix + "article_albums where article_id=" + article_id);
if (!string.IsNullOrEmpty(id_list))
{
strSql.Append(" and id not in(" + id_list + ")");
}
DataSet ds = DbHelperOleDb.Query(conn, trans, strSql.ToString());
foreach (DataRow dr in ds.Tables[0].Rows)
{
int rows = DbHelperOleDb.ExecuteSql(conn, trans, "delete from " + databaseprefix + "article_albums where id=" + dr["id"].ToString()); //删除数据库
if (rows > 0)
{
Utils.DeleteFile(dr["thumb_path"].ToString()); //删除缩略图
Utils.DeleteFile(dr["original_path"].ToString()); //删除原图
}
}
}
示例4: PrepareCommand
/// <summary>
/// This method opens (if necessary) and assigns a connection, transaction, command type and parameters
/// to the provided command.
/// </summary>
/// <param name="command">the OleDbCommand to be prepared</param>
/// <param name="connection">a valid OleDbConnection, on which to execute this command</param>
/// <param name="transaction">a valid OleDbTransaction, or 'null'</param>
/// <param name="commandType">the CommandType (stored procedure, text, etc.)</param>
/// <param name="commandText">the stored procedure name or PL/SQL command</param>
/// <param name="commandParameters">an array of OleDbParameters to be associated with the command or 'null' if no parameters are required</param>
private static void PrepareCommand( OleDbCommand command, OleDbConnection connection, OleDbTransaction transaction, CommandType commandType, string commandText, OleDbParameter[] commandParameters )
{
//if the provided connection is not open, we will open it
if( connection.State != ConnectionState.Open )
{
connection.Open();
}
//associate the connection with the command
command.Connection = connection;
//set the command text (stored procedure name or OleDb statement)
command.CommandText = commandText;
//if we were provided a transaction, assign it.
if( transaction != null )
{
command.Transaction = transaction;
}
//set the command type
command.CommandType = commandType;
//attach the command parameters if they are provided
if( commandParameters != null )
{
AttachParameters( command, commandParameters );
}
return;
}
示例5: AsDataSource
/// <summary>
/// Returns a data source wrapped around the transaction.
/// </summary>
/// <param name="connection">The connection.</param>
/// <param name="transaction">The transaction.</param>
/// <returns>SqlServerOpenDataSource.</returns>
/// <exception cref="ArgumentNullException"></exception>
public static AccessOpenDataSource AsDataSource(this OleDbConnection connection, OleDbTransaction transaction)
{
if (connection == null)
throw new ArgumentNullException(nameof(connection), $"{nameof(connection)} is null.");
if (connection.State == ConnectionState.Closed)
connection.Open();
var dataSourceBase = s_CachedDataSources.GetOrAdd(connection.ConnectionString, cs => new AccessDataSource(cs));
return new AccessOpenDataSource(dataSourceBase, connection, transaction);
}
示例6: ExecuteNoQuery
public static int ExecuteNoQuery(CommandType commType, string commText, OleDbParameter[] param, OleDbTransaction tran)
{
int result = 0;
using (OleDbConnection conn = new OleDbConnection(connectString))
{
PrepareCommand(conn, comm, commType, commText, param, tran);
result = comm.ExecuteNonQuery();
}
return result;
}
示例7: OleDbCustomCommandBuilder
public OleDbCustomCommandBuilder( DataTable dataTable, OleDbConnection connection, ArrayList columnOleDbTypes, OleDbTransaction transaction)
{
if (dataTable.Columns.Count != columnOleDbTypes.Count){
throw new ArgumentException("Number of OleDbTypes does not match number of columns.");
}
this.dataTable = dataTable;
this.connection = connection;
this.columnOleDbTypes = columnOleDbTypes;
this.transaction = transaction;
}
示例8: GenerateDay
void GenerateDay(OleDbConnection connection, OleDbTransaction transaction, int n, DateTime day) {
double totalDays = day.Subtract(minRequiredDate).TotalDays;
int salesPerDay = random.Next(180, (int)(200 * (1 + (totalDays * dailySalesGrowth) / 10)));
int[] generateIntervals = GenerateTimeIntervals(salesPerDay);
DateTime start = new DateTime(day.Year, day.Month, day.Day, startTime, 0, 0);
for(int d = 0; d < generateIntervals.Length; d++) {
for(int x = 0; x < generateIntervals[d]; x++)
GenerateSale(connection, transaction, start);
start = start.AddMinutes(timeInterval);
}
}
示例9: BeginTransaction
public void BeginTransaction()
{
this.Open();
this.cmd = this.connection.CreateCommand();
this.transaction = this.connection.BeginTransaction();
this.cmd.Transaction = this.transaction;
}
示例10: Commit
public void Commit()
{
if (connection==null) throw new PersistException("No current connection");
if (transaction==null) throw new PersistException("No transaction to commit");
transaction.Commit();
transaction=null;
}
示例11: Init
private void Init(JetProcessor processor, IEnumerable<string> columnDefinitions)
{
Connection = processor.Connection;
Transaction = processor.Transaction;
Create(columnDefinitions);
}
示例12: DBBase
public DBBase(IDbConnection conn)
{
this._connection = null;
this._transaction = null;
this.DB_Driver_Type = "OleDb";
this._connection = (OleDbConnection) conn;
}
示例13: TestBeginTransactionChaos
public void TestBeginTransactionChaos() {
DataBaseServer dbType = ConnectedDataProvider.GetDbType(con);
// not supported on DB2 and Oracle and Sybase
if (dbType != DataBaseServer.Oracle && dbType != DataBaseServer.DB2 && dbType != DataBaseServer.Sybase) {
con.Close();
con.Open();
try {
BeginCase("BeginTransaction - IsolationLevel Chaos");
tran = con.BeginTransaction(IsolationLevel.Chaos);
Compare(tran == null, false);
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
}
/* not supported by MSSQL,DB2,Oracle
con.Close();
con.Open();
try
{
BeginCase("BeginTransaction - IsolationLevel Unspecified");
tran = con.BeginTransaction(IsolationLevel.Unspecified );
Compare(tran == null, false);
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
*/
}
示例14: WorkDB
/// <summary>
/// Конструктор
/// </summary>
/// <param name="aConnectionString">строка соединения</param>
public WorkDB(string aConnectionString)
{
mCn = new OleDbConnection(aConnectionString);
mErr = new Error();
mTxn = null;
mIsInternalTransaction = false;
}
示例15: product_service
public int product_service(string service_id, string product_id, int customer_id)
{
int row=0;
cn = new OleDbConnection("Provider=MSDAORA;Data Source=192.168.0.217/orcl;Persist Security Info=True;User ID=hr;Password=hr;");
cmd = cn.CreateCommand();
try
{
cn.Open();
string s = "update product_services set product_id='" + product_id + "' where service_id=(select service_id from customer_services where customer_id=" + customer_id + " and service_id='" + service_id + "')";
Trans = cn.BeginTransaction();
cmd = new OleDbCommand(s, cn,Trans);
cmd.Transaction = Trans;
row= cmd.ExecuteNonQuery();
Trans.Commit();
}
catch (Exception e)
{
string s = e.Message;
Trans.Rollback();
}
finally
{
cn.Close();
}
return row;
}