I'm having problem With a Null reference exception Error message when running the later part of the code. i.e
FYI:
Sort Out The problem and give the exact cause. Thanks In advance.
Code:
trans.Rollback()
Code:
Dim trans As OleDbTransaction
Try
trans = con.BeginTransaction
If con.State = ConnectionState.Closed Then
con.Open()
End If
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)
cmd_inward.Transaction = trans
cmd_inward.ExecuteNonQuery()
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)
cmd_pur_mast.Transaction = trans
cmd_pur_mast.ExecuteNonQuery()
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)
cmd_prd_mast.Transaction = trans
cmd_prd_mast.ExecuteNonQuery()
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)
Dim rdr As OleDbDataReader
rdr = cmd_select_warehouse.ExecuteReader()
If rdr.Read() = False Then
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)
cmd_insert.Transaction = trans
cmd_insert.ExecuteNonQuery()
Else
MessageBox.Show("data")
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)
cmd_update.Transaction = trans
cmd_update.ExecuteNonQuery()
End If
trans.Commit()
Catch ex As Exception
trans.Rollback()
MessageBox.Show("Transaction Rolled Back")
Finally
con.Close()
End Try