数据导出处理办法, 有没有更好的方法?
从SAP系统中导出数据到SQL中,现在只能一条一条的Insert,大家有没有其它方法?
代码如下:
----------------------------------------------------------------
Set conn = New ADODB.Connection
conn.Open "provider=sqloledb;server=192.168.10.1;uid=web;pwd=web;database=website"
If oConnection Is Nothing Then
'MsgBox "Ready to Logon Now..."
Set SAPLogonControl1 = CreateObject("SAP.LogonControl.1")'SAP登录
Set oConnection = SAPLogonControl1.NewConnection
oConnection.Client = "500"
oConnection.User = "web"
oConnection.Password = "web"
oConnection.ApplicationServer = "192.168.10.6"
oConnection.SystemNumber = "00"
LogonInfo = oConnection.Logon(wac.hWnd, True)
End If
If oConnection.IsConnected <> tloRfcConnected Then
mystring = "系统无法登陆!"
mytextfile.writeline (mystring)
mytextfile.writeblanklines (1)
mytextfile.Close
Unload Me
Exit Sub
End If
'***************
Rem Create Functions Object
Set SAPFunction = CreateObject("SAP.Functions")'SAP BAPI 调用
Set SAPFunction.Connection = oConnection
Set oFunc = SAPFunction.Add("BAPI_SALES_ORDERS")
If Not oFunc.Call Then
Exit Sub
End If
'*********************************
sql = "delete from salesinfo"
conn.Execute (sql)
For i = 1 To oFunc.Tables("TSALESINFO").RowCount
sql = "insert into salesinfo values('" & oFunc.Tables("TSALESINFO")(i, "VBELN") & "'," & oFunc.Tables("TSALESINFO")(i, "POSNR") & ",'" & oFunc.Tables("TSALESINFO")(i, "AUDAT") & "','" & oFunc.Tables("TSALESINFO")(i, "BSTNK") & "', " & _
"'" & oFunc.Tables("TSALESINFO")(i, "MATNR") & "'," & oFunc.Tables("TSALESINFO")(i, "KWMENG") & ",'" & oFunc.Tables("TSALESINFO")(i, "VRKME") & "','" & oFunc.Tables("TSALESINFO")(i, "LFGSA") & "'," & _
" " & oFunc.Tables("TSALESINFO")(i, "NETPR") & "," & oFunc.Tables("TSALESINFO")(i, "NETWR") & ",'" & oFunc.Tables("TSALESINFO")(i, "WAERK") & "','" & oFunc.Tables("TSALESINFO")(i, "VSTEL") & "'," & _
"'" & oFunc.Tables("TSALESINFO")(i, "ROUTE") & "','" & oFunc.Tables("TSALESINFO")(i, "WERKS") & "','" & oFunc.Tables("TSALESINFO")(i, "ZTERM") & "','" & oFunc.Tables("TSALESINFO")(i, "INCO1") & "'," & _
"'" & oFunc.Tables("TSALESINFO")(i, "INCO2") & "','" & oFunc.Tables("TSALESINFO")(i, "KNKLI") & "','" & oFunc.Tables("TSALESINFO")(i, "KUNAG") & "','" & oFunc.Tables("TSALESINFO")(i, "KUNWE") & "','" & oFunc.Tables("TSALESINFO")(i, "SDABW") & "')"
' Debug.Print sql
conn.Execute (sql)
Next
----------------------------------------------------------------
把sql串起来再 conn.execute(sql)的不算, 大家有没有其它更好的办法?