Bir çok Google çalışanından sonra, bir veritabanına bağlanmayı, mevcut geçici tabloyu bırakmayı ve ardından bir yeni bir (doldurun ve sonuçları görüntüleyin).SQL Server 2008'de bir Excel Makrosu (ADODB) kullanarak bir geçici tablo oluşturma
Dim adoCn As ADODB.Connection
Dim adoRs As ADODB.Recordset
Dim adoCm As ADODB.Command
Dim strSQL As String
Set adoCn = New ADODB.Connection
With adoCn
.ConnectionString = "Provider=SQLOLEDB;" & _
"Initial_Catalog=XXX;" & _
"Integrated Security=SSPI;" & _
"Persist Security Info=True;" & _
"Data Source=XXX;" & _
"Extended Properties='IMEX=1'"
.CursorLocation = adUseServer
.Open
End With
Set adoCm = New ADODB.Command
With adoCm
Set .ActiveConnection = adoCn
.CommandType = adCmdText
.CommandText = "IF OBJECT_ID('tempdb..#AgedProducts') IS NOT NULL DROP TABLE #AgedProducts"
.Execute
.CommandText = "CREATE TABLE #AgedProducts " & _
"(Source_Order_Number VARCHAR(255)) " & _
"INSERT INTO #AgedProducts VALUES ('AB-123-456') " & _
"SELECT * FROM #AgedProducts (NOLOCK) "
.Execute
End With
Set adoRs = New ADODB.Recordset
With adoRs
Set .ActiveConnection = adoCn
.LockType = adLockBatchOptimistic
.CursorLocation = adUseServer
.CursorType = adOpenForwardOnly
.Open "SET NOCOUNT ON"
End With
adoRs.Open adoCm
MsgBox "Recordset returned...", vbOKOnly
While Not adoRs.EOF
Debug.Print adoRs.Fields(0).Value
adoRs.MoveNext
Wend
adoCn.Close
Set adoCn = Nothing
Set adoRs = Nothing
ben aşağıdaki hata mesajı alıyorum sorgu çalıştırdığınızda: (Yukarıdaki kod çok yaptığı gibi)
Run-time error '-2147217887 (80040e21)':
The requested properties cannot be supported
NOCOUNT
hat http://support.microsoft.com/kb/235340 geliyor. Sipariş numarasının çok sayıda türü olabileceğini hesaba katmak için IMEX=1
ekledim, ancak sorunun oluştuğu şüphesi var.
Herhangi bir yardım büyük beğeni topluyor!
Bunun için teşekkürler - bir muamele çalışır. Bunun benim ilk denemem yerine neden çalıştığını biliyor musun? –
Recodset'in içinde neyin gerektiğini bilmesi gerekiyor, bu yüzden SQL kodunu sağlamanız gerekiyor. Bir göz atın, ör. burada http://support.microsoft.com/kb/168336. Rehberin nasıl açılacağı konusunda farklı yöntemler var. İyi günler. – dee