471,337 Members | 802 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

using trigger in C# Windows Form

Hi,

MyForm is a C# Windows Form.
MyFom has 3 GroupBoxes.
Now I wanna update data from the textboxes in those 3 GroupBoxes.
I have function Update1 for GroupBox1 to update table Table1, Update2 for
GroupBox2 to update table Table2, Update3 for GroupBox3 to update table
Table3.
And there is a function TotalUpdate for MyForm.
The function TotalUpdate comprises of Update1, Update2, and Update3.
Now my question is how do I RollBack the Update1 if the Update3 fails?
How do I incurr a trigger in my C# code?
Thanks for help.
Jason
Jan 12 '06 #1
3 4012
Use a Transaction.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"Jason Huang" <Ja************@hotmail.com> wrote in message
news:OE**************@TK2MSFTNGP14.phx.gbl...
Hi,

MyForm is a C# Windows Form.
MyFom has 3 GroupBoxes.
Now I wanna update data from the textboxes in those 3 GroupBoxes.
I have function Update1 for GroupBox1 to update table Table1, Update2 for
GroupBox2 to update table Table2, Update3 for GroupBox3 to update table
Table3.
And there is a function TotalUpdate for MyForm.
The function TotalUpdate comprises of Update1, Update2, and Update3.
Now my question is how do I RollBack the Update1 if the Update3 fails?
How do I incurr a trigger in my C# code?
Thanks for help.
Jason

Jan 12 '06 #2
Thanks Kevin.
But I am wondering how a transaction can be split into 3 functions and works
as a single transaction?
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> ¼¶¼g©ó¶l¥ó·s»D:%2***************@TK2MSFTNGP09.phx. gbl...
Use a Transaction.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"Jason Huang" <Ja************@hotmail.com> wrote in message
news:OE**************@TK2MSFTNGP14.phx.gbl...
Hi,

MyForm is a C# Windows Form.
MyFom has 3 GroupBoxes.
Now I wanna update data from the textboxes in those 3 GroupBoxes.
I have function Update1 for GroupBox1 to update table Table1, Update2 for
GroupBox2 to update table Table2, Update3 for GroupBox3 to update table
Table3.
And there is a function TotalUpdate for MyForm.
The function TotalUpdate comprises of Update1, Update2, and Update3.
Now my question is how do I RollBack the Update1 if the Update3 fails?
How do I incurr a trigger in my C# code?
Thanks for help.
Jason


Jan 16 '06 #3
Transactions can happily span multiple DB requests. The traditional way
would be to create an ADO transaction and hand it around for objects
(calling to the database) to enlist within, but unless you own all the code
performing the changes it can be hard to do this.

However, under 2.0 (and especially if you are using SQL-Server 2005) most
(all?) inbuilt database calls respect the new TransactionScope entity - this
creates an "ambient transaction" which can work (broadly: read up on MSDN2
for more info) as an ADO transaction or a DTC transaction, yet requires very
little work: in particular, you don't need to explicitely pass the
transaction to all of the callers.

Example (note: you need to reference System.Transactions and add an "using"
clause)

using(TransactionScope transaction = new TransactionScope()) {
SomeMethodThatUpdatesTheDatabase();
SomeOtherMethodThanUpdatesTheDatabase();
YouveGuessedItIAlsoUpdateTheDatabase();
transaction.Compete();
}

If anything throws an exception, transaction is disposed without ever
calling Complete(); this causes the transaction to rollback, and your
changes are undone. If Complete() *is* called. the transaction is committed.

Marc
Jan 16 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Terri | last post: by
7 posts views Thread by Sjaak van Esdonk | last post: by
9 posts views Thread by Lauren Quantrell | last post: by
3 posts views Thread by itp | last post: by
14 posts views Thread by raylopez99 | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.