473,811 Members | 3,610 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Transaction Problem

19 New Member
I'm having problem With a Null reference exception Error message when running the later part of the code. i.e
Expand|Select|Wrap|Line Numbers
  1. trans.Rollback()
  2.  
FYI:
Expand|Select|Wrap|Line Numbers
  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
  40.  
  41.  
Sort Out The problem and give the exact cause. Thanks In advance.
Dec 31 '10 #1
0 1024

Sign in to post your reply or Sign up for a free account.

Similar topics

3
4735
by: rkusenet | last post by:
Hi, I am still not very proficient in SQLServer. So apology if the question sounds basic. We have a script to clean old unwanted data. It basically deletes all rows which are more than 2 weeks old. It deletes data from 33 tables and the number of rows in each table runs into few millions. What I see in the script (not written by me :-) ) is that all data is deleted within a single BEGIN TRANSACTION and COMMIT TRANSACTION. As
7
1583
by: denis | last post by:
Hello I'm trying to run this code but i get an error: "Object reference not set to an instance of an object. " Can somebody help me? Thanks Try '***************************************************************************
4
3558
by: Ramesh | last post by:
hi I am trying to insert random values to the tables. I will get no.of records value from user, based on that loop will start to insert records. For this insertion i am using stored procedure. I am using Transaction for each insert statement. But when i try to insert it is displaying "use of unassigned local variable 'InsertTrans'. Can anybody help me. My code is as follows.
2
2307
by: Beenz | last post by:
Hello, I am developing an application in C#, which was previously in .Net 2005 Beta, then it was working perfectly fine, but from the time I have upgraded it to .Net 2.0 Professional, its continously giving me error on the following line, transaction = Connection.BeginTransaction(); System.Data.SqlClient.SqlException: New transaction is not allowed because
9
7621
by: John Sidney-Woollett | last post by:
Is it possible to use the dblink and dblink_exec features from inside pl/pgsql functions to mimic the behaviour of nested transactions by calling another function or executing some SQL via the dblink (into the same database)? Does the SQL statement executed within the dblink sit in its own isolated transaction/session? And would an error thrown in the dblink statement abort the enclosing session that initiated the call? What is the...
1
3971
by: pb648174 | last post by:
I just wanted to post a follow up to a message I posted some months ago about a long running transaction that was blocking all other users... The link is below http://groups.google.com/group/comp.databases.ms-sqlserver/browse_thread/thread/1063b65df1f97492/8649bee2002646a2 By using the new "Row versioning" functionality of SQL 2005, it completely solved this problem. By reading the books online, it says there is a performance impact,...
2
5774
by: Habib | last post by:
CREATE PROCEDURE SimpleInsert ( @custname custname_type, @carname carname_type) AS BEGIN TRANSACTION INSERT Customers (CustName) VALUES (@custname)
0
1815
by: Matik | last post by:
Hi, MSSQL 2000 booth servers. Booth running DTC. Now, the client application, is starting in DB1 a procedure. The connection open to db, is within the transation opened from client. In the SP, I'm starting the transaction as well, with savepoint.
1
1047
by: alenak | last post by:
Hi Everybody, I have a web application that makes large number of insertions and updates in DB. In this application I send a sql query which is sql transaction shown below. The problem is that SOMETIMES one of tables naming 'AimD' has no record although table 'AimB' has a record.But according to transaction it must HAVE. A very important consideration is that the table 'AimD' is getting 1 million records everyday and approximately 1 to 7...
1
2322
kiemxai
by: kiemxai | last post by:
you see that,i did correct or not? PROBLEM ANALYSIS For an introduction to program transaction journal, see the background section of assignment . Not only transaction journal, but also inventory sheet is needed to print at the end of the day. It is the list of items, inventory cost, inventory units, and inventory amount When items of the same type were purchased at different unit cost, it is the question as to how to calculate the unit...
0
9724
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10644
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10127
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9201
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7665
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6882
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5552
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.