我有一个简单的sql批量插入语句,在sql mgmt工作室中运行良好。我试图从.vbs文件运行sql命令。这是我的vbscript代码。它一直到msgbox并显示消息。它没有显示任何错误,因此它似乎正在完成,但数据库中的表是空白的,因此没有导入任何数据。我错过了什么?
option explicit
Dim objConn
Dim objRS
Dim strSQL
Dim ConnectionString
Dim fso
Dim objArgs
ConnectionString = "Provider=SQLOLEDB;Server=mtgops047-db006;Database=interlinqe3;Trusted_Connection=yes"
Set objConn = CreateObject ("ADODB.Connection")
Set objRS = CreateObject ("ADODB.RecordSet")
Set fso = CreateObject("Scripting.FileSystemObject")
objConn.Open ConnectionString
strSQL = "delete from Settlement_Import_Data"
strSQL = strSQL & " BULK INSERT Settle_Import_Data"
strSQL = strSQL & " FROM '\\server\sharedfolder\importdata.txt' with"
strSQL = strSQL & " ( FIELDTERMINATOR =',', ROWTERMINATOR = '\n')"
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
MsgBox ("Update Complete!")
WScript.Quit()
答案 0 :(得分:0)
objConn.Execute()一次为您的删除语句并再次调用它为您的批量插入语句解决了问题。谢谢!