INSERT problems.

  • Thread starter Thread starter Tull Clancey
  • Start date Start date
T

Tull Clancey

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.
 
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
'***
 
Apologies for not making it clearer. Thanks, this is just the answer!

Cheers,
Tull.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top