Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Database Access / March 2008



Tip: Looking for answers? Try searching our database.

Create temp table on SQL server?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Matt Williamson - 27 Mar 2008 16:49 GMT
Is there some trick to creating a temp table on a SQL server through the ADO
connection object? This code works fine if I create a permanent table, but
doesn't do anything if I add the # to create a temp table

Option Explicit
Public oCon As ADODB.Connection

Sub OpenConnection()

Dim sConnectString As String

Set oCon = New ADODB.Connection

sConnectString = "Provider=sqloledb;" & _
          "Data Source=Server\Instance1;" & _
          "Initial Catalog=DBToUse;" & _
          "Integrated Security=SSPI"

oCon.Open sConnectString

End Sub

Sub CloseConnection()
   If Not oCon Is Nothing Then
       If (oCon.State And adStateOpen) = adStateOpen Then
           oCon.Close
       End If
       Set oCon = Nothing
   End If
End Sub

Sub CreateDatesTable(sDate1 As String, sDate2 As String)

Dim sSQL As String

OpenConnection
sSQL = "Create table DateRange(id int primary key, Dates datetime NOT NULL)
" -- works
'sSQL = "Create table #DateRange(id int primary key, Dates datetime NOT
NULL) " --doesn't work
oCon.Execute sSQL

'sSQL = "insert into #DateRange (id, Dates) values (1, '" & sDate1 & "')"
'oCon.Execute sSQL
'sSQL = "insert into #DateRange (id, Dates) values (2, '" & sDate2 & "')"
'oCon.Execute sSQL

CloseConnection

End Sub

TIA

Matt
Jan Hyde (VB MVP) - 27 Mar 2008 17:11 GMT
"Matt Williamson" <ih8spam@spamsux.org>'s wild thoughts were
released on Thu, 27 Mar 2008 11:49:18 -0400 bearing the
following fruit:

>Is there some trick to creating a temp table on a SQL server through the ADO
>connection object? This code works fine if I create a permanent table, but
>doesn't do anything if I add the # to create a temp table

How do you determine if anything has happened?

You close the connection immediately and the temp table will
go with it.

J

>Option Explicit
>Public oCon As ADODB.Connection
[quoted text clipped - 46 lines]
>
>Matt

--
Jan Hyde

https://mvp.support.microsoft.com/profile/Jan.Hyde
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.