Hi,
When I try to update different tables using Transaction I get the following error;
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceExcept
ion: Object reference not set to an instance of an object.
Source Error:
Line 335: InTrans.Rollback()
update sub;
Dim InCommand As Data.OleDb.OleDbCommand = Con.CreateCommand()
Dim InTrans As Data.OleDb.OleDbTransactio
n
If Con.State <> ConnectionState.Open Then
Con.Open()
End If
Try
rdr = cmd1.ExecuteReader
If rdr.Read Then
NewTotalIN = rdr.Item("TotalIN")
If NewTotalIN = "" Or IsDBNull(NewTotalIN) Or Not IsNumeric(NewTotalIN) Then NewTotalIN = 0
Response.Write(NewTotalIN)
End If
rdr.Close()
rdr = cmd2.ExecuteReader
If rdr.Read Then
sum1 = rdr.Item("TotalOUT")
If sum1 = "" Or IsDBNull(sum1) Or Not IsNumeric(sum1) Then sum1 = 0
End If
rdr.Close()
rdr = cmd3.ExecuteReader
If rdr.Read Then
sum2 = rdr.Item("TotalOUT2")
If sum2 = "" Or IsDBNull(sum2) Or Not IsNumeric(sum2) Then sum2 = 0
End If
rdr.Close()
rdr = cmd4.ExecuteReader
If rdr.Read Then
txtROL = rdr.Item("ROL")
If txtROL = "" Or IsDBNull(txtROL) Or Not IsNumeric(txtROL) Then txtROL = 0
End If
rdr.Close()
rdr = cmd5.ExecuteReader
If rdr.Read Then
txtOldQtyIN = rdr.Item("QtyIn")
If txtOldQtyIN = "" Or IsDBNull(txtOldQtyIN) Or Not IsNumeric(txtOldQtyIN) Then txtOldQtyIN = 0
End If
rdr.Close()
If ((NewTotalIN) - (txtOldQtyIN) + txtQtyIn) < ((sum1) + ((sum2) + txtROL)) Then
Response.Write("<script language='JavaScript'>aler
t('You cannot update.');</script>")
found = 1
End If
If found = 0 Then
InTrans = Con.BeginTransaction()
InCommand.Connection = Con
InCommand.Transaction = InTrans
InCommand.CommandText = UpdateStr1
InCommand.ExecuteNonQuery(
)
InCommand.CommandText = UpdateStr2
InCommand.ExecuteNonQuery(
)
Response.Write("<script language='JavaScript'>aler
t('Spare Parts IN updated successfully!');</script>"
)
InTrans.Commit()
End If
Catch ex1 As Exception
Try
InTrans.Rollback()
Catch ex As OleDbException
If Not InTrans.Connection Is Nothing Then
Console.WriteLine("An exception of type " & ex.GetType().ToString & _
" was encountered while attempting to roll back the transaction.")
End If
End Try
'Catch ex As OleDbException
Console.WriteLine("An exception of type " & e.GetType().ToString() & _
"was encountered while inserting the data.")
Console.WriteLine("Neither
record was written to database.")
Finally
Con.Close()
End Try
can anyone pls. help me to solve the problem?
ayha