473,544 Members | 2,219 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4193
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******** ******@TK2MSFTN GP14.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***@DIESPAMM ERSDIEtakempis. 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******** ******@TK2MSFTN GP14.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 TransactionScop e 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.Transact ions and add an "using"
clause)

using(Transacti onScope transaction = new TransactionScop e()) {
SomeMethodThatU pdatesTheDataba se();
SomeOtherMethod ThanUpdatesTheD atabase();
YouveGuessedItI AlsoUpdateTheDa tabase();
transaction.Com pete();
}

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
10830
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 @strcmdshell varchar(150)
7
1803
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 is used in database B. Currently triggers are being used to update the data on database B when anything changes on database A. Working this way...
9
11208
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 only one column: txtOutput I want to use the DB front end (MS Access) to send the text string to the SQL backend, then have the SQL Server create a...
2
3094
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 tables of the same names. A third table BusinessRel records the BusinessID (linked to Business table) and OwnerID (linked to Owner table). This is...
5
1825
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 click event gets handled by the user class. I want the event to be passed to the Windows form (not the user control). So I am guessing that I...
3
2410
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 the onchange event ot submit a request. Has anyone tried this and could maybe provide an example? ref: http://www.ajaxtoolbox.com/about/
2
3562
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 If TypeOf ctrl Is TextBox Then txtbox = CType(ctrl, TextBox) AddHandler txtbox.ModifiedChanged, AddressOf TextBoxChanged
5
1674
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 change the color of the button to Coral, and show a MessageBox with the button name. So far, I've tried the below event handlers, and the only one...
14
2943
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 reason you would want to do this is for example to trigger something from an OnPaint event without resorting to boolean switches-- say if a user...
0
7438
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7374
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7720
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5931
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4930
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3422
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1850
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
996
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
677
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.