*Transaction is concept of executing a set of DML(Data Manipulation Language) statements at same time.
*If we want more than one DML statements to execute at a time then we need transaction.
*If all statements of transaction are executed successfully then it should call commit method even one statement is failed then it should call rollback method.
*For transaction implementation we have class called OleDbTransaction (for oledb).
Open access data base and create bank table
Create new windows forms application
*Drag and drop 3 labels, 3 textboxes and 2 button controls.
*Design of form is below
*Go to Form1.cs and write the below code
public partial class Form1 : Form
OleDbConnection cn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E://srid documents/mydocsssssss/products.accdb;User ID=admin");
foreach (Control c in this.Controls)
if (c.GetType() == typeof(TextBox))
((TextBox)(c)).Text = string.Empty;
private void button2_Click(object sender, EventArgs e)
private void Form1_Load(object sender, EventArgs e)
private void button1_Click(object sender, EventArgs e)
string s1 = "update bank set amount=amount-" + textBox3.Text + "
where accountno=" + textBox1.Text;
string s2 = "update bank set amount=amount+" + textBox3.Text + "
where accountno=" + textBox2.Text;
OleDbTransaction tran = cn.BeginTransaction();
OleDbCommand cmd = new OleDbCommand(s1, cn, tran);
int x = cmd.ExecuteNonQuery();
OleDbCommand cmd2 = new OleDbCommand(s2, cn, tran);
int y = cmd2.ExecuteNonQuery();
if (x == 0 || y == 0)
MessageBox.Show("Your Transaction failed...!");
MessageBox.Show("Your Transaction is succesfull...!");
*Press control+F5 and run the application
Please visit my article in the given below not only inline query i had given for sqlBulkcopy
Thanks for acknowledging,
I have visited your article and it is good.
You have given both
1.How to Use Transactions in SqlBulkCopy.
2.How to use Transactions for an Inline query.
I have did lnline query transaction with the help of small windows application.
This is good article.
But as per my knowledge and experience you should use only one OledbCommand instead of cmd and cmd2. Single transaction will work on single command by executing query one by one.
Hope you don't mind.