简体   繁体   English

VBScript SQL批量插入语句

[英]VBScript SQL Bulk Insert Statement

I have a simple sql bulk insert statement that works well inside sql mgmt studios. 我有一个简单的sql批量插入语句,该语句在sql mgmt studios内部很好地工作。 I'm trying to run the sql command from a .vbs file. 我正在尝试从.vbs文件运行sql命令。 Here is my vbscript code. 这是我的vbscript代码。 It makes it all the way to the msgbox and displays the message. 它一直到msgbox并显示消息。 It doesn't show any errors so it appears to be completing, but the table is blank in the db so no data was imported. 它没有显示任何错误,因此似乎已完成,但是数据库中的表为空白,因此未导入任何数据。 What am I missing? 我想念什么?

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()

objConn.Execute() once for your delete statement and call it again for your bulk insert statement solved the issue. 一次对您的delete语句使用objConn.Execute(),然后对您的批量插入语句再次调用它即可解决此问题。 Thanks! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM