473,396 Members | 1,833 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,396 software developers and data experts.

INSERT problems.

Hi All.

I'm using VB.NET ADO - OLEDB connection to an Access database. I'm having a
problem with Inserting data and viewing the results immediately afterwards.

I have a routine that opens a database Connection, sets a Command and runs
an ExecuteNonQuery to Insert a row into a table.

I then run another routine which sets up a Connection and DataAdapter which
fills a DataSet with the modified data above.

The problem is the Adapter appears to retrieve the data before the NonQuery
has inserted the row. What I need is a way to force the write of the
NonQuery before I close it's connection.

In VB6 I would have turned to the BeginTransaction and EndTransaction, but
this doesn't appear to be the same in Net.

Any ideas?

Cheers,
Tull.
Nov 21 '05 #1
2 1028
Hi Tull ! :O)
In VB6 I would have turned to the BeginTransaction and EndTransaction, but
this doesn't appear to be the same in Net.


What do you mean ?
You tried it and it failed or you're just not sure how to do it ?

here's a quick sample just in case (not tested) :
'***
Dim cmd As New OleDbCommand()
cmd.CommandType = CommandType.Text
cmd.CommandText = "insert into t1(f1, f2, fn) values('1', '2', '3' )"
cmd.Connection = New OleDbConnection(my_conn_string)
cmd.Connection.Open()

Dim tr As OleDbTransaction = cmd.Connection.BeginTransaction()
Try
cmd.ExecuteNonQuery()
tr.Commit()
Catch (ex As Exception)
tr.Rollback()
Finally
cmd.Connection.Close()
End Try
'***

--
Best Regards
Yanick
Nov 21 '05 #2
Apologies for not making it clearer. Thanks, this is just the answer!

Cheers,
Tull.

"Zoury" <yanick_lefebvre at hotmail dot com> wrote in message
news:uA**************@TK2MSFTNGP10.phx.gbl...
Hi Tull ! :O)
In VB6 I would have turned to the BeginTransaction and EndTransaction,
but
this doesn't appear to be the same in Net.


What do you mean ?
You tried it and it failed or you're just not sure how to do it ?

here's a quick sample just in case (not tested) :
'***
Dim cmd As New OleDbCommand()
cmd.CommandType = CommandType.Text
cmd.CommandText = "insert into t1(f1, f2, fn) values('1', '2', '3' )"
cmd.Connection = New OleDbConnection(my_conn_string)
cmd.Connection.Open()

Dim tr As OleDbTransaction = cmd.Connection.BeginTransaction()
Try
cmd.ExecuteNonQuery()
tr.Commit()
Catch (ex As Exception)
tr.Rollback()
Finally
cmd.Connection.Close()
End Try
'***

--
Best Regards
Yanick

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: me | last post by:
I'm also having problems getting the bulk insert to work. I don't know anything about it except what I've gleened from BOL but I'm not seeming to get anywhere...Hopefully there is some little (or...
14
by: serge | last post by:
I have a scenario where two tables are in a One-to-Many relationship and I need to move the data from the Many table to the One table so that it becomes a One-to-One relationship. I need to...
8
by: Carl | last post by:
Hi, I hope someone can share some of their professional advice and help me out with my embarissing problem concerning an Access INSERT query. I have never attempted to create a table with...
4
by: G.Esmeijer | last post by:
Friends When I use a Querystring for insertdating data into a Tabel (going to SQLserver) the decimal pint changes to a comma. The result is that I get a system error (which I can understand) ...
2
by: John Tyce | last post by:
When a button is clicked, a date is inserted or added into a combo box like this : ComboBox.Items.Add(string) or ComboBox.Items.Insert(0,string); Either way, the new string does not show up in the...
3
by: nolanmadson | last post by:
I'm creating a front-end for some Teradata user maintenance tables in MS Access. I've started having problems in occasionally not being able to insert or update records in these tables. I've been...
1
by: =?Utf-8?B?SGFycnkgS2Vjaw==?= | last post by:
I have a GridView that I dynamically add columns to in code. The way that my code is written, everything works properly if I use GridView.Columns.Add to simply add the columns to the end of the...
5
by: Rob | last post by:
I'm trying to use the set<my_class>::insert( my_class const & ) method, but have run into some problems. It seems like I'm seeing it insert an object when a similar object is already in the set. ...
0
BenRatcliffe
by: BenRatcliffe | last post by:
Hi there, I was wondering if anyone could help me. I have a comlpex database with a number of forms that have data entered on them and then saved into the correct table etc. In this instance I am...
2
by: Terry Reedy | last post by:
SUBHABRATA, I recommend you study this excellent response carefully. castironpi wrote: It starts with a concrete test case -- an 'executable problem statement'. To me, this is cleared and...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...

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.