By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,932 Members | 1,455 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,932 IT Pros & Developers. It's quick & easy.

Transaction object question

P: n/a
REB
If I create a transaction object for rolling back a insert query in the on
click event of a form button can the transaction be tracked across other
functions?

For example:

private void btnSaveDriver_Click(object sender, System.EventArgs e)

{

Create transaction object

Execute a insert query into a primary table

Call_Funtion_One(int primary_key_from_intial_insert)

Call_Funtion_Two(int Primarykey)

on error rollback everything exectued above

}

Call_Funtion_One(int Primarykey)

{

Execute query to insert data in a related table using key passed into the
function

}

Call_Funtion_Two(int Primarykey)

{

Execute query to insert data in a related table using key passed into the
function

}

I hope what I am asking makes sense, if not please let me know and I will
try to elaborate further.
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

To track the transaction, you will need to pass a
reference to the transaction object to the functions you
call.

A better way to do it might be like this:

try{
create connection
create transaction

call func1() //performs inserts/updates
call func2() //performs inserts/updates
...
}catch(Exception x){
transaction.Rollback()
}
transaction.Commit()

OR
you could inherit your business classes from
ServicedComponent and use the COM+ features for
transaction management.

HTH
Regards
Harsh Thakur
-----Original Message-----
If I create a transaction object for rolling back a insert query in the onclick event of a form button can the transaction be tracked across otherfunctions?

For example:

private void btnSaveDriver_Click(object sender, System.EventArgs e)
{

Create transaction object

Execute a insert query into a primary table

Call_Funtion_One(int primary_key_from_intial_insert)

Call_Funtion_Two(int Primarykey)

on error rollback everything exectued above

}

Call_Funtion_One(int Primarykey)

{

Execute query to insert data in a related table using key passed into thefunction

}

Call_Funtion_Two(int Primarykey)

{

Execute query to insert data in a related table using key passed into thefunction

}

I hope what I am asking makes sense, if not please let me know and I willtry to elaborate further.
.

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.