-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: chocoGee
Message 2 in Discussion

Hi,   I think these couple of sentences will make it clear.   Transactions are a group 
of database operations combined into a logical unit of work, and are used to control 
and maintain the consistency and integrity of each database despite errors that might 
occur in the system. A transaction consists of a series of SQL SELECT, INSERT, UPDATE, 
or DELETE statements. If no errors are encountered during a transaction, all 
modifications in the transaction become a permanent part of the database. If errors 
are encountered, none of the modifications are made to the database.  
For example, in a banking application where funds are transferred from one account to 
another, one account is credited an amount, and another account is debited the same 
amount at the same time. Because computers can fail due to power outages, network 
outages, and so on, it is possible to update a row in one table, but not in the 
related table. If your database supports transactions, you can group database 
operations into a transaction to prevent database inconsistency resulting from these 
events. 
There are three basic commands for transactions: BEGIN, COMMIT, and ROLLBACK. The 
BEGIN statement marks the beginning of a transaction. All procedures attempted after 
the BEGIN statement are considered part of the transaction, which is completed by the 
COMMIT statement, or canceled by the ROLLBACK statement. 
The following example demonstrates transactional logic using Transact-SQL.BEGIN TRAN 
INSERT INTO account (account,amount,debitcredit) values (100,100,'d') INSERT INTO 
account (account,amount,debitcredit) values (300,100,'c') IF (@@ERROR > 0)   ROLLBACK 
ELSE   COMMIT 
In ADO.NET, you control transactions using the Connection and Transaction objects. 
To perform a transaction        Call the BeginTransaction method of the Connection 
object to mark the start of the transaction. BeginTransaction returns a reference to 
the Transaction. Retain this reference so that you can assign it to Commands that are 
enlisted in the transaction.      Assign the Transaction object to the Transaction 
property of the Command to be executed. If a Command is executed on a Connection with 
an active Transaction and the Transaction object has not been assigned to the 
Transaction property of the Command, an exception will be thrown.          Execute the 
required commands.          Call the Commit method of the Transaction object to 
complete the transaction, or call the Rollback method to cancel the transaction.  
The following code example demonstrates transactional logic using ADO.NET with 
Microsoft� SQL Server�.[Visual Basic] Dim myConnection As SqlConnection = New 
SqlConnection("Data Source=localhost;Initial Catalog=Northwind;Integrated 
Security=SSPI;") myConnection.Open()  ' Start a local transaction. Dim myTrans As 
SqlTransaction = myConnection.BeginTransaction()  ' Enlist the command in the current 
transaction. Dim myCommand As SqlCommand = New SqlCommand myCommand.Transaction = 
myTrans  Try   myCommand.CommandText = "Insert into Region (RegionID, 
RegionDescription) VALUES (100, 'Description')"   myCommand.ExecuteNonQuery()   
myCommand.CommandText = "Insert into Region (RegionID, RegionDescription) VALUES (101, 
'Description')"   myCommand.ExecuteNonQuery()   myTrans.Commit()   
Console.WriteLine("Both records are written to database.") Catch e As Exception   
myTrans.Rollback()   Console.WriteLine(e.ToString())   Console.WriteLine("Neither 
record was written to database.") Finally   myConnection.Close() End Try Rgds,Geetha

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/BDOTNET/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you received 
this message by mistake, please click the "Remove" link below. On the pre-addressed 
e-mail message that opens, simply click "Send". Your e-mail address will be deleted 
from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to