473,396 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 4182
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Terri | last post by:
I'm using xp_cmdshell to output a text file from a trigger like this CREATE TRIGGER ON tblApplications FOR INSERT AS DECLARE @FirstName varchar(75) DECLARE @LastName varchar(75) Declare...
7
by: Sjaak van Esdonk | last post by:
Hi all, i'm trying to find a solution for the following problem: I have two different database called A and B. On database A runs an application call AA. Some information from the database A...
9
by: Lauren Quantrell | last post by:
Is there a way to create a text file (such as a Windows Notepad file) by using a trigger on a table? What I want to do is to send a row of information to a table where the table: tblFileData has...
2
by: Terry | last post by:
Hello, I wonder if anyone can shed light on this problem for me. I have an Access 97 front end with an SQL 2000 database. There is a Business main form with an Owner subform and corresponding...
5
by: Guy Noir | last post by:
I have a quick question on custom controls. I have a control that I created with a class that extends the NumericUpDown control. My problem is that when I use this usercontrol on my form, the...
3
by: itp | last post by:
I have moved to Matt Kruse's Javascript Toolbox. It has some great examples to get you going quickly! Unfortunately all the examples are based on a form/submit model. I would like to try using...
2
by: Alan Mailer | last post by:
Ok, I'm pretty new to VB.Net, so please bear with me. Imagine the Load event of one of my forms includes the following: Dim ctrl as Control Dim txtbox As TextBox For Each ctrl In Me.Controls...
5
by: raylopez99 | last post by:
I have a form, Form6, that has a bunch of buttons overlaid on it. I want to be able to click on any arbitrary area of the form, and if that area of the form is overlaid by a button, I want to...
14
by: raylopez99 | last post by:
KeyDown won't work KeyPress fails KeyDown not seen inspired by a poster here:http://tinyurl.com/62d97l I found some interesting stuff, which I reproduce below for newbies like me. The main...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.