Hello everybody
I have problem with disconnected mode and transaction
it's give to me ERROR message
in this lineExecuteReader requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized
PHP Code:da.InsertCommand = cb.GetInsertCommand
my code is:
PHP Code:
Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("DBCon").ConnectionString)
Dim cmd As New SqlCommand("insert into Customer (customer_id, customer_name, note) values (@cid, @cname, @note)", con)
Dim da As New SqlDataAdapter("select * from CustomerPhone", con)
Dim dt As New DataTable
Dim trans As SqlTransaction
Dim cb As New SqlCommandBuilder(da)
dt = CType(ViewState("dt"), DataTable)
cmd.Parameters.AddWithValue("@cid", txtID.Text)
cmd.Parameters.AddWithValue("@cname", txtName.Text)
cmd.Parameters.AddWithValue("@note", txtNote.Text)
Try
con.Open()
trans = con.BeginTransaction(IsolationLevel.ReadCommitted)
cmd.Transaction = trans
da.InsertCommand = cb.GetInsertCommand 'ERROR message
da.InsertCommand.Transaction = trans
cmd.ExecuteNonQuery() 'insert into customer table
da.Update(dt)
trans.Commit()
Catch ex As Exception
trans.Rollback()
Finally
con.Close()
End Try
![]()





Reply With Quote