GR M

GR M

  • NA
  • 5
  • 22.7k

Null reference exception in Transaction

Dec 31 2010 2:09 AM
Im having problem with a null reference exception while executing the code
trans.Rollback() . Kindly help ASAP.
Thanx in Advance.
FYI:
  1. Dim trans As OleDbTransaction  
  2.    
  3.         Try  
  4.             trans = con.BeginTransaction  
  5.             If con.State = ConnectionState.Closed Then  
  6.                 con.Open()  
  7.             End If  
  8. Dim cmd_inward As OleDbCommand = New OleDbCommand("Insert into inward_entry(in_date,product_name,batch_no,Pack,type, qty,Description,Mfd_Company,Exp_Date,Purchased_price,MRP) values (#" & Todate & "#,'" & Prd_nm & "', '" & Prd_batch & "','" & Prd_pack & "', '" & prd_type & "','" & item_Qty & "', '" & prd_description & "','" & Mfd_By & "','" & exp_dt & "', '" & Pur_prc & "','" & Prd_MRP & "')", con)  
  9.             cmd_inward.Transaction = trans  
  10.             cmd_inward.ExecuteNonQuery()  
  11.             Dim cmd_pur_mast As OleDbCommand = New OleDbCommand("insert into purchase_master (purchase_date,product_name,item_pack,Batch_no,product_purchase_price,item_qty) values (#" & Todate & "#, '" & Prd_nm & "','" & Prd_pack & "','" & Prd_batch & "', '" & Pur_prc & "','" & item_Qty & "')", con)  
  12.             cmd_pur_mast.Transaction = trans  
  13.             cmd_pur_mast.ExecuteNonQuery()  
  14.             Dim cmd_prd_mast As OleDbCommand = New OleDbCommand("insert into product_master(product_name, item_pack,product_manufacturer,product_description) values ('" & Prd_nm & "','" & Prd_pack & "','" & Mfd_By & "','" & prd_description & "')", con)  
  15.             cmd_prd_mast.Transaction = trans  
  16.             cmd_prd_mast.ExecuteNonQuery()  
  17. Dim cmd_select_warehouse As OleDbCommand = New OleDbCommand("Select * from warehouse_master where product_batch_no='" & Prd_batch & "' and  product_name='" & Prd_nm & "' and item_pack='" & Prd_pack & "' ", con)  
  18.             Dim rdr As OleDbDataReader  
  19.             rdr = cmd_select_warehouse.ExecuteReader()  
  20. If rdr.Read() = False Then  
  21. Dim cmd_insert As OleDbCommand = New OleDbCommand("Insert into warehouse_master(product_batch_no, product_manufacturer, product_name,item_pack, available_qty,product_exp_date,product_MRP) values('" & Prd_batch & "','" & Mfd_By & "','" & Prd_nm & "', '" & Prd_pack & "','" & item_Qty & "', '" & exp_dt & "', '" & Prd_MRP & "')", con)  
  22.                 cmd_insert.Transaction = trans  
  23.                 cmd_insert.ExecuteNonQuery()  
  24.    
  25.             Else  
  26.                 MessageBox.Show("data")  
  27.                 Dim cmd_update As OleDbCommand = New OleDbCommand("Update warehouse_master set available_qty= available_qty + '" & item_Qty & "' where product_batch_no = '" & Prd_batch & "' and product_Name = '" & Prd_nm & "' and Item_pack= '" & Prd_pack & "'", con)  
  28.                 cmd_update.Transaction = trans  
  29.                 cmd_update.ExecuteNonQuery()  
  30.  End If  
  31.    
  32.             trans.Commit()  
  33.         Catch ex As Exception  
  34.  trans.Rollback()  
  35.    
  36.             MessageBox.Show("Transaction Rolled Back")  
  37.         Finally  
  38.             con.Close()  
  39.         End Try 
 

Answers (7)