Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 24th, 2007, 09:42 AM
Authorized User
 
Join Date: Aug 2006
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default SQL Transaction

hi friends

i need one transaction

in which i am using one command object

to delete all the records from table where userid = "?"

and

one dataadapter and command builder
 using this i am adding multiple rows in the same table

what should be the code for this

i tried this but it gave me some transaction error

thanks

 
Old January 24th, 2007, 09:52 AM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Well

Please clarify your issue a bit more, & post the code that you have written, so that we can help you accordingly.

Regards
Mike

Fortune favours the brave, so don't regret on missed oppurtunities.
 
Old January 24th, 2007, 11:59 PM
Authorized User
 
Join Date: Aug 2006
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dim tran As SqlTransaction

            Try
                If cn.State = ConnectionState.Closed Then cn.Open()
                tran = cn.BeginTransaction
                Dim cmdDeleteUserActions As New SqlCommand("DELETE FROM UserActionDetails WHERE UserId = " & UserID, cn,tran)
                updateUserActionDetails = cmdDeleteUserActions.ExecuteNonQuery()

                Dim daUpdateUserActions As New SqlDataAdapter("SELECT * FROM UserActionDetails", cn)
                Dim cmdBuilder As New SqlCommandBuilder(daUpdateUserActions)
                Dim ds As New DataSet

                daUpdateUserActions.Fill(ds, "UserActionDetails")
                Dim dRow As DataRow
                Dim rowNo As Int16 = 0
                While rowNo < al.Count
                    dRow = ds.Tables("UserActionDetails").NewRow
                    dRow(0) = UserID
                    dRow(1) = al.Item(rowNo)
                    dRow(2) = 1
                    ds.Tables("UserActionDetails").Rows.Add(dRow)
                    rowNo += 1
                End While
                daUpdateUserActions.Update(ds, "UserActionDetails")
                tran.Commit()
                cmdDeleteUserActions.Dispose()
                cn.Close()
            Catch ex As Exception
               tran.Rollback()
                strEx = ex.Message
            Finally
                cn.Close()
            End Try
        End Function






Similar Threads
Thread Thread Starter Forum Replies Last Post
sql server transaction prrocess id 635 benn Reporting Services 0 March 22nd, 2006 07:06 AM
Transaction across 2 DBs joelchaconf Classic ASP Professional 0 March 9th, 2006 05:17 AM
Transaction on MYSQL ?? soeleistiyo MySQL 2 September 17th, 2004 07:15 AM
how to use Transaction ? locka ADO.NET 0 August 12th, 2003 08:48 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.