473,396 Members | 1,748 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.

Result of INSERT statement not showing up in following SELECT statement

I am using ADO to run some SQL statements in Access.

First, I run query to create a table using SELECT . . . INTO Table A.

Then, I run a query to SELECT . . . FROM Table A to get some data and
the table is empty.

This appears to be a timing issue because the second query works when
I run it in ACCESS instead of in VB following the first statement.

What is the problem?

How do I know that the first statement has been completed (or
committed) before running the second one?

Thank you.
Nov 13 '05 #1
6 1696
On Sun, 14 Aug 2005 17:12:30 GMT, David <bo***********@yahoo.com> wrote:
I am using ADO to run some SQL statements in Access.

First, I run query to create a table using SELECT . . . INTO Table A.

Then, I run a query to SELECT . . . FROM Table A to get some data and
the table is empty.

This appears to be a timing issue because the second query works when
I run it in ACCESS instead of in VB following the first statement.

What is the problem?

How do I know that the first statement has been completed (or
committed) before running the second one?

Thank you.


Are you using the same connection instance for each statement?
Nov 13 '05 #2
On Sun, 14 Aug 2005 10:41:47 -0700, Steve Jorgensen
<no****@nospam.nospam> wrote:
On Sun, 14 Aug 2005 17:12:30 GMT, David <bo***********@yahoo.com> wrote:
I am using ADO to run some SQL statements in Access.

First, I run query to create a table using SELECT . . . INTO Table A.

Then, I run a query to SELECT . . . FROM Table A to get some data and
the table is empty.

This appears to be a timing issue because the second query works when
I run it in ACCESS instead of in VB following the first statement.

What is the problem?

How do I know that the first statement has been completed (or
committed) before running the second one?

Thank you.


Are you using the same connection instance for each statement?


Yes.
Nov 13 '05 #3
On Sun, 14 Aug 2005 10:41:47 -0700, Steve Jorgensen
<no****@nospam.nospam> wrote:
On Sun, 14 Aug 2005 17:12:30 GMT, David <bo***********@yahoo.com> wrote:
I am using ADO to run some SQL statements in Access.

First, I run query to create a table using SELECT . . . INTO Table A.

Then, I run a query to SELECT . . . FROM Table A to get some data and
the table is empty.

This appears to be a timing issue because the second query works when
I run it in ACCESS instead of in VB following the first statement.

What is the problem?

How do I know that the first statement has been completed (or
committed) before running the second one?

Thank you.


Are you using the same connection instance for each statement?

My first reply was incorrect.

I have a utility module that I pass a SQL statement to for processing.
I made the module so that I wouldn't have to write the same code in
every program. Was this a bad idea? Can I commit a record in Access
similar to Oracle?

I use this to run the statement:

Set recSet = Utilities.Run_SQL(sqlStmt)

The utilities module looks like this:
Option Explicit
Dim db_file As String
Dim sqlStmt As String
Dim dbConn As ADODB.Connection
Dim recSet As ADODB.Recordset
Dim strClient As String

Public Function Run_SQL(SQLs As String) As ADODB.Recordset
Make_Connection

sqlStmt = SQLs

Run_SQL_Stmt

Set Run_SQL = recSet

End Function

Private Sub Make_Connection()
' MsgBox "Entering make_connection"

'Set the database
db_file = "C:\Current Database\new.mdb"

'Open a connection to the database
Set dbConn = New ADODB.Connection

dbConn.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & db_file & ";" & _
"Persist Security Info=False"

dbConn.Open (dbConn.ConnectionString)

End Sub

Private Sub Run_SQL_Stmt()
'Run the statement
On Error GoTo ExecuteError

Set recSet = dbConn.Execute(sqlStmt, , adCmdText)

Exit Sub

ExecuteError: frmInvoicing.txtSQLText.Text =
frmInvoicing.txtSQLText.Text & _
vbCrLf & _
"*** Error executing command in Utilities.RunSQL_Stmt ***"
& _
vbCrLf & Err.Description & vbCrLf & sqlStmt
Exit Sub

End Sub

Thanks for your help.

David
Nov 13 '05 #4
On Sun, 14 Aug 2005 17:50:03 GMT, David <bo***********@yahoo.com> wrote:
On Sun, 14 Aug 2005 10:41:47 -0700, Steve Jorgensen
<no****@nospam.nospam> wrote:
On Sun, 14 Aug 2005 17:12:30 GMT, David <bo***********@yahoo.com> wrote:
I am using ADO to run some SQL statements in Access.

First, I run query to create a table using SELECT . . . INTO Table A.

Then, I run a query to SELECT . . . FROM Table A to get some data and
the table is empty.

This appears to be a timing issue because the second query works when
I run it in ACCESS instead of in VB following the first statement.

What is the problem?

How do I know that the first statement has been completed (or
committed) before running the second one?

Thank you.


Are you using the same connection instance for each statement?

My first reply was incorrect.

I have a utility module that I pass a SQL statement to for processing.
I made the module so that I wouldn't have to write the same code in
every program. Was this a bad idea? Can I commit a record in Access
similar to Oracle?


This is specifically a problem with JET, and if I remember correctly, it does
will not occur if you use the same DAO Connection or the same DAO Database
instance for every call. JET has transactions, and it also has a
DBEngine.Idle call (DAO only) that the documentation says will flush all
unwritten data to the datatbase. Neither of these seems to help, though.

Regarding whether your common code was a bad idea, no, removing duplication is
good, you just need a way to open one connection, save it in a variable, and
always use that connection. I like the lazy initialization approach...

private mcnn As ADODB.Connectino

Private Function GetConnection()
Const cstrDbFile = "C:\Current Database\new.mdb"

If mcnn is Nothing Then
Set mcnn = New ADODB.Connection

mcnn.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & cstrDbFile & ";" & _
"Persist Security Info=False"

mcnn.Open (dbConn.ConnectionString)
End If

Set GetConnection = mcnn
End Function

Private Sub CloseConnection()

If mcnn is Nothing Then Exit Sub
mcnn.Close
Set mcnn = Nothing

End Sub

Each procedure that needs a connection, now calls this GetConnection to get
it. At the exit point of the program, call CloseConnection to clean up
nicely.
Nov 13 '05 #5
On Sun, 14 Aug 2005 11:16:40 -0700, Steve Jorgensen
<no****@nospam.nospam> wrote:
On Sun, 14 Aug 2005 17:50:03 GMT, David <bo***********@yahoo.com> wrote:
On Sun, 14 Aug 2005 10:41:47 -0700, Steve Jorgensen
<no****@nospam.nospam> wrote:
On Sun, 14 Aug 2005 17:12:30 GMT, David <bo***********@yahoo.com> wrote:

I am using ADO to run some SQL statements in Access.

First, I run query to create a table using SELECT . . . INTO Table A.

Then, I run a query to SELECT . . . FROM Table A to get some data and
the table is empty.

This appears to be a timing issue because the second query works when
I run it in ACCESS instead of in VB following the first statement.

What is the problem?

How do I know that the first statement has been completed (or
committed) before running the second one?

Thank you.

Are you using the same connection instance for each statement?

My first reply was incorrect.

I have a utility module that I pass a SQL statement to for processing.
I made the module so that I wouldn't have to write the same code in
every program. Was this a bad idea? Can I commit a record in Access
similar to Oracle?


This is specifically a problem with JET, and if I remember correctly, it does
will not occur if you use the same DAO Connection or the same DAO Database
instance for every call. JET has transactions, and it also has a
DBEngine.Idle call (DAO only) that the documentation says will flush all
unwritten data to the datatbase. Neither of these seems to help, though.

Regarding whether your common code was a bad idea, no, removing duplication is
good, you just need a way to open one connection, save it in a variable, and
always use that connection. I like the lazy initialization approach...

private mcnn As ADODB.Connectino

Private Function GetConnection()
Const cstrDbFile = "C:\Current Database\new.mdb"

If mcnn is Nothing Then
Set mcnn = New ADODB.Connection

mcnn.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & cstrDbFile & ";" & _
"Persist Security Info=False"

mcnn.Open (dbConn.ConnectionString)
End If

Set GetConnection = mcnn
End Function

Private Sub CloseConnection()

If mcnn is Nothing Then Exit Sub
mcnn.Close
Set mcnn = Nothing

End Sub

Each procedure that needs a connection, now calls this GetConnection to get
it. At the exit point of the program, call CloseConnection to clean up
nicely.


Thanks a lot.

That explains it. I will use your example.

Thanks again.

Nov 13 '05 #6
On Sun, 14 Aug 2005 11:16:40 -0700, Steve Jorgensen
<no****@nospam.nospam> wrote:

private mcnn As ADODB.Connectino

Private Function GetConnection()
Const cstrDbFile = "C:\Current Database\new.mdb"

If mcnn is Nothing Then
Set mcnn = New ADODB.Connection

mcnn.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & cstrDbFile & ";" & _
"Persist Security Info=False"

mcnn.Open (dbConn.ConnectionString)
End If

Set GetConnection = mcnn
End Function

Private Sub CloseConnection()

If mcnn is Nothing Then Exit Sub
mcnn.Close
Set mcnn = Nothing

End Sub

Each procedure that needs a connection, now calls this GetConnection to get
it. At the exit point of the program, call CloseConnection to clean up
nicely.


Perfect.

I put it in my module and it worked great.

Thanks a lot.
Nov 13 '05 #7

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

Similar topics

1
by: per | last post by:
im not very good at sql but need to query the database to use in my programming script. if the database is just like this id name parent_id 1 A ...
1
by: shottarum | last post by:
I currently have 2 tables as follows: CREATE TABLE . ( mhan8 int, mhac02 varchar(5), mhmot varchar(5), mhupmj int )
4
by: teddysnips | last post by:
I am trying to insert a row into a table using a stored procedure and I get the following error if I try this from QA: INSERT failed because the following SET options have incorrect settings:...
4
by: John Baker | last post by:
Hi: Most of the time when I do a query and it has no matches, there is a single blank line in the result that I can test. I have one query where no result produces a response with NO lines at...
4
by: Chris Kratz | last post by:
Hello all, We have run into what appears to be a problem with rules and subselects in postgres 7.4.1. We have boiled it down to the following test case. If anyone has any thoughts as to why...
11
by: Eugene Anthony | last post by:
The code bellow functions well when I attemp to delete a record. But when I attemp to insert a record I am getting the following error -2147217900:Syntax error in INSERT INTO statement. How do I...
3
by: Beowulf | last post by:
I was just messing around with some ad hoc views and table returning UDFs today so I could look at and print out data from a small table and noticed something strange. If I stick my select...
8
by: nano2k | last post by:
Hi Shortly, I keep invoices in a table. Occasionally, someone will fire the execution of a stored procedure (SP) that performs several UPDATEs against (potentially) all invoices OLDER than a...
9
by: serge | last post by:
/* Subject: How to build a procedure that returns different numbers of columns as a result based on a parameter. You can copy/paste this whole post in SQL Query Analyzer or Management Studio...
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: 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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.