昨天測試了這段程式半天,總提示ODBC呼叫錯誤,老是找不到錯誤出現在那里,無限郁闷中;今天早上一上班就繼續找問題出現在那里,我昏倒,原來是Table HST已經存在于DB中,于是乎修改StrlSQL為:strSQL = "insert INTO [odbc;Driver={SQL Server};Server=NJBPRINT01;Database=barcode;UID=sa;PWD=njbarcode].hst select * FROM [test$]",OK,成功.哎,一個簡單的語法錯誤讓我想了半天.
Dim cn As ADODB.Connection
Dim strSQL As String
Dim lngRecsAff As Long
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\test\test.xls;" & _
"Extended Properties=Excel 8.0"
'Import by using Jet Provider.
strSQL = "select * INTO [odbc;Driver={SQL Server};Server=NJBPRINT01;Database=barcode;UID=sa;PWD=barcode].hst FROM [test$]"
Debug.Print strSQL
cn.Execute strSQL, lngRecsAff, adExecuteNoRecords
MsgBox "Inport Successfully"
Debug.Print "Records affected: " & lngRecsAff
cn.Close
Set cn = Nothing
|Archiver|小黑屋|手机版|壹佰网 ERP100
( 京ICP备19053597号-2 )
GMT+8, 2025/11/29 18:15 , Processed in 0.007974 second(s), 12 queries , File On.
Powered by Discuz! X3.4
Copyright © 2001-2020, Tencent Cloud.