Solved

ADO - 2 part sql statement

Posted on 2004-08-27
3
215 Views
Last Modified: 2013-11-23
Using ADO connected to a SQL Server database I want to populate a recordset with a 2 part query. In a simplified version, something like this:

rs.Open "Select * Into #Temp From ATable  Select * From #Temp"

What I want returned to the recordset is the contents of the temp table. When I run this I don't get an error but the recordset state is closed. I know that I could add a stored procedure to the database but want to do this through ado if possible.

Any ideas?
0
Comment
Question by:jgv
3 Comments
 
LVL 3

Expert Comment

by:rinksno1
ID: 11918957
as you said you want all the records from the temp table
use


connectionstring="provider=sqloledb.1;uid=sa;pwd=;data source=servername;initial catalog=database1"
rs.ActiveConnection = ConnectionString
rs.CursorLocation = adUseClient

rs.open "Select * from temp", , dOpenStatic, adLockReadOnly

now iterate through the recordset

***********

rinks
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 250 total points
ID: 11918972
Use this:

rs.Open "SET NOCOUNT ON Select * Into #Temp From ATable  Select * From #Temp SET NOCOUNT OFF"
0
 
LVL 12

Author Comment

by:jgv
ID: 11919009
Thanks emoreau, that did it. Now that you pointed out the nocount it makes sense. I've been caught by this in the past; just didn't think of it in this case.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now