473,383 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Help with Transactions and Data Adapters

I wrote a little program to import XML data into a SQL Table. The XML tags are the names of the SQL Columns. It works fine except when I get an exception (i.e. foreign key contraint problem) halfway through the XML file, I end up with half my records processed. So Transactions should solve the problem, right? Well I am getting the error about The Transaction property of the command has not been initialized. It happens when the Adapter is being filled - even though the fill is only to get the column headers. Any help would be appreciated.

Expand|Select|Wrap|Line Numbers
  1.         Dim objSQLTransaction As SqlTransaction
  2.         Dim objSQLConn As SqlConnection
  3.         Try
  4.             objSQLConn = New SqlConnection("SERVER=" & Me.txtServername.Text & ";UID=" & Me.txtUsername.Text & ";PWD=" & Me.txtPassword.Text & ";DATABASE=" & Me.txtAccount.Text & ";")
  5.             Dim strTableName As String = Me.txtSQLTable.Text
  6.             Dim objAdapter As SqlDataAdapter
  7.             Dim objDataRow, objDBRow As DataRow
  8.             Dim objDataColumn As DataColumn
  9.             Dim objDSXML As New DataSet()
  10.             Dim objDSDBTable As New DataSet(strTableName)
  11.             Dim ObjCmdBuilder As SqlCommandBuilder
  12.             objDSXML.ReadXml(Me.txtFilename.Text)
  13.             objSQLConn.Open()
  14.             objSQLTransaction = objSQLConn.BeginTransaction()
  15.             objAdapter = New SqlDataAdapter("SELECT * FROM " & strTableName & " WHERE 1 = 2", objSQLConn)
  16.             objAdapter.Fill(objDSDBTable, strTableName)
  17.             For Each objDataRow In objDSXML.Tables(0).Rows
  18.                 With objDSDBTable.Tables(0)
  19.                     objDBRow = .NewRow()
  20.                     For Each objDataColumn In objDSXML.Tables(0).Columns
  21.                         objDBRow(objDataColumn.ColumnName) = objDataRow(objDataColumn.ColumnName)
  22.                      Next
  23.                     .Rows.Add(objDBRow)
  24.                 End With
  25.                 objCmdBuilder = New SqlCommandBuilder(objAdapter)
  26.                 objAdapter.Update(objDSDBTable, strTableName)
  27.             Next
  28.             objSQLTransaction.Commit()
  29.         Catch ex As Exception
  30.             objSQLTransaction.Rollback()
  31.         Finally
  32.             objSQLConn.Close()
  33.         End Try
  34.  
Aug 10 '07 #1
0 812

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

Similar topics

3
by: JIMMIE WHITAKER | last post by:
The below stored procedure works. However, I am trying to use a text box from a temp form for the where clause. WHERE Transactions.TransactionID = !! I even tried changing first line: Alter...
7
by: Richard Maher | last post by:
Hi, I am seeking the help of volunteers to test some software that I've developed which facilitates distributed two-phase commit transactions, encompassing any resource manager (e.g. SQL/Server...
11
by: Mike P | last post by:
I've been using C# transactions for a while and had no problems with them. Using try catch blocks I can trap basically all possible errors and rollback all necessary data. Over the last few...
1
by: bob1barker | last post by:
we are creating a database of sales agents. Basically I have a table of about 35,000 people, a second one with 8000 offices, and a third table of around 400,000 transactions done by those 35,000...
0
by: Ben Dewey | last post by:
Guys, I am new to the System.Transactions namespace, but I am trying to use it to process powerpoint document into a database. I have a strongly typed DataSet with Talks and Slides. Both...
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
11
by: Maria Mela | last post by:
Hello everyone... Anybody can help me on this project?? Thks for your time... Requirements Information: of the Card Each card will have a set of information associated. These information...
6
by: Randy | last post by:
Hi, I'm trying to fill a combobox with values from a sql table. Data seems to be connected fine. Apparently in VB Express sqlDataAdapter doesn't work, or at least I can't make it work. ...
2
by: jigneshluhar | last post by:
1) What is the commonly fixed database role of a db_datawriter? a) Add, change or delete data from all the tables b) Assign statement and object permissions c) Backup and restore databases...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.