sql adapter transaction problem

adwaitjoshi

Active member
Joined
Dec 29, 2005
Messages
38
Programming Experience
1-3
Hi I have the following code
VB.NET:
 Dim cb As New SqlCommandBuilder(_sqladapter)
_sqladapter.UpdateCommand = cb.GetUpdateCommand()
_sqladapter.InsertCommand = cb.GetInsertCommand()
_sqladapter.DeleteCommand = cb.GetDeleteCommand()
_sqladapter.Update(_dataset.Tables(_tablename))
the above code works fine out of a transaction. When I say BeginTransaction I get an error
Error updating SQL Adapter. The exception Execute requires the command to have a transaction object when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized..
hence I added the code
VB.NET:
_sqladapter.UpdateCommand.Transaction = gobjDatabase.CurrentTransaction
_sqladapter.InsertCommand.Transaction = gobjDatabase.CurrentTransaction
_sqladapter.DeleteCommand.Transaction = gobjDatabase.CurrentTransaction

_sqladapter.UpdateCommand = cb.GetUpdateCommand()
_sqladapter.InsertCommand = cb.GetInsertCommand()
_sqladapter.DeleteCommand = cb.GetDeleteCommand()
_sqladapter.Update(_dataset.Tables(_tablename))
now I get an error

Error updating SQL Adapter. The exception Object reference not set to an instance of an object..
what am I doing wrong? Can someone please guide me?
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,557
Location
Norway
Programming Experience
10+
Try to assign the SqlTransaction instance returned by BeginTransaction method. (before Update method)
 
Top Bottom