本地excel导入到远程sql
我的代码,只能导入到本机sql
Dim a As String
Dim strSQL As String
Dim lngRecsAff As Long
Set cn = New ADODB.Connection
cn.Open "Provider=SQLOLEDB;Data Source=" & strServerName & ";" & _
"Initial Catalog=123;User ID=sa;Password=sa"
strSQL = " insert into B1_Order ([cInvName],[dDate1],[cOrder],[cCustomer],[cfabric) select [规格],[接单日期],[订单号],[客户],[规格] FROM OpenDataSource('MICROSOFT.JET.OLEDB.4.0','Excel 5.0;HDR=YES;DATABASE=" & Text1.Text & ";')...[sheet1$] "
cn.Execute strSQL, lngRecsAff, adExecuteNoRecords
Debug.Print "Records affected: " & lngRecsAff
MsgBox "导入" & lngRecsAff & "条记录成功!"
cn.Close
Set cn = Nothing
[解决办法]
先用VB创建远程SQL数据库:http://www.doc88.com/p-617721597230.html