R
Richard
Hi,
I have 1 dataset with 2 tables (Table1 as parent, Table2 as Child), 1 row in
both the tables.
I am updating it with a transaction. First parent then child.
When child update fails, it raise an exception, and rollback the parent
update. But it also change the rowstate of the parent row from Added to
unchanged
When you try to save again parent row never get created in database. So
child update will fail again.
Please suggest what am I suppose to do to update both parent and child.
This is what I am doing. This is just a SAMPLE code.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim sTransaction As SqlClient.SqlTransaction
SqlConnection1.Open()
sTransaction = SqlConnection1.BeginTransaction
Try
daTable1.InsertCommand.Transaction = sTransaction
daTable1.UpdateCommand.Transaction = sTransaction
daTable1.DeleteCommand.Transaction = sTransaction
daTable1.Update(ds)
daTable2.InsertCommand.Transaction = sTransaction
daTable2.UpdateCommand.Transaction = sTransaction
daTable2.DeleteCommand.Transaction = sTransaction
daTable2.Update(ds)
sTransaction.Commit()
Catch ex As Exception
sTransaction.Rollback()
MsgBox(ex.Message)
Finally
SqlConnection1.Close()
End Try
End Sub
Please advise me.Thanks in advance,
RC
I have 1 dataset with 2 tables (Table1 as parent, Table2 as Child), 1 row in
both the tables.
I am updating it with a transaction. First parent then child.
When child update fails, it raise an exception, and rollback the parent
update. But it also change the rowstate of the parent row from Added to
unchanged
When you try to save again parent row never get created in database. So
child update will fail again.
Please suggest what am I suppose to do to update both parent and child.
This is what I am doing. This is just a SAMPLE code.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim sTransaction As SqlClient.SqlTransaction
SqlConnection1.Open()
sTransaction = SqlConnection1.BeginTransaction
Try
daTable1.InsertCommand.Transaction = sTransaction
daTable1.UpdateCommand.Transaction = sTransaction
daTable1.DeleteCommand.Transaction = sTransaction
daTable1.Update(ds)
daTable2.InsertCommand.Transaction = sTransaction
daTable2.UpdateCommand.Transaction = sTransaction
daTable2.DeleteCommand.Transaction = sTransaction
daTable2.Update(ds)
sTransaction.Commit()
Catch ex As Exception
sTransaction.Rollback()
MsgBox(ex.Message)
Finally
SqlConnection1.Close()
End Try
End Sub
Please advise me.Thanks in advance,
RC