DataSet transaction : Transaction « Database ADO.net « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » Database ADO.net » TransactionScreenshots 
DataSet transaction
DataSet transaction

Imports System
Imports System.Xml
Imports System.Xml.Schema
Imports System.IO
Imports System.Data.SqlClient
Imports System.Collections
Imports System.Data


Public Class MainClass
    
    Shared Sub Main()
        Dim ConnectionString As String
        Dim myconnection As SqlConnection
        Dim mytransaction As SqlTransaction
        Dim mycommand1 As SqlCommand
        Dim myparam As SqlParameter
        Dim da As SqlDataAdapter
        Dim ds As New DataSet()
        Dim args() As String = Environment.GetCommandLineArgs

        ConnectionString = "Server=(local)\SQLEXPRESS;Initial Catalog=MyDatabase;Integrated Security=SSPI"
        myconnection = New SqlConnection(ConnectionString)
        myconnection.Open()

        da = New SqlDataAdapter("select * from Employee", myconnection)
        da.Fill(ds, "Employee")
        myconnection.Close()

        ds.Tables(0).Rows(0)("FirstName""11"

        mycommand1 = New SqlCommand("update Employee set FirstName=@FirstName " "where ID=@ID ", myconnection)
        myparam = New SqlParameter("@ID", SqlDbType.SmallInt)
        myparam.SourceColumn = "ID"
        myparam.SourceVersion = DataRowVersion.Current
        mycommand1.Parameters.Add(myparam)

        myparam = New SqlParameter("@FirstName", SqlDbType.Int)
        myparam.SourceColumn = "FirstName"
        myparam.SourceVersion = DataRowVersion.Current
        mycommand1.Parameters.Add(myparam)

        myconnection.Open()
        mytransaction = myconnection.BeginTransaction()
        mycommand1.Transaction = mytransaction
        da.UpdateCommand = mycommand1
        Try
            da.Update(ds, "Employee")
            mytransaction.Commit()
            Console.WriteLine("Order modified successfully !")
        Catch As Exception
            mytransaction.Rollback()
            Console.WriteLine(e.Message)
        Finally
            myconnection.Close()
        End Try
    End Sub
End Class



           
       
Related examples in the same category
1.Simple Transaction Commit and RollBack: SqlTransaction has completed; it is no longer usable.Simple Transaction Commit and RollBack: SqlTransaction has completed; it is no longer usable.
2.Transaction save point and roll back
3.Transaction Rollback Demo
4.Transaction Commit Demo
5.Isolation Level ReadUncommittedIsolation Level ReadUncommitted
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.