使用VBScript将数据从Excel导入到SQL Server时,空白值传递到数据库

我正在试图开发一个vbs导入数据从Excel到SQL服务器。 字节值正在被导入,但是在DB的varchar字段中,来自Excel的string值没有被导入(字段为空)。 下面是代码

Option Explicit Const adOpenStatic = 3 Const adLockOptimistic = 3 dim strSqlInsertString,objConnection2,objRecordSet2 dim objExcel,objWorkBook,strRow Set objConnection2 = CreateObject("ADODB.Connection") Set objRecordSet2 = CreateObject("ADODB.Recordset") objConnection2.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=appapollo;Password=dna;Initial Catalog=6057;Data Source=lxi282" Set objExcel = CreateObject("Excel.Application") Set objWorkbook = objExcel.Workbooks.Open _ ("D:\Cardiopacs\Automation\Forward\test.xls") strRow = 2 dim AEName,AEDescription,AEIPAddress,AEPort,ModifiedDate,QRSSApplicationEntityID,MobileAE,NotificationXML,PreFetch,PreFetchSuffix strSqlInsertString = "INSERT INTO SSDICOMApplicationEntities (AEName,AEDescription,AEIPAddress,AEPort,ModifiedDate,QRSSApplicationEntityID,MobileAE," & _ "NotificationXML,PreFetch,PreFetchSuffix) " & _ "VALUES('" &AEName& "','" &AEDescription& "','" &AEIPAddress& "','" &AEPort& "','" &ModifiedDate& "','" &QRSSApplicationEntityID& "','" &MobileAE& "'," & _ "'" &NotificationXML& "','" &PreFetch& "','" &PreFetchSuffix& "')" Do Until objExcel.Cells(strRow,1).Value = "" 'SSDIOMApplicationEntityID = objExcel.Cells(intRow, 1).Value AEName = objExcel.Cells(strRow, 1).Value AEDescription = objExcel.Cells(strRow, 2).Value AEIPAddress = objExcel.Cells(strRow, 3).Value AEPort = objExcel.Cells(strRow, 4).Value ModifiedDate = objExcel.Cells(strRow, 5).Value QRSSApplicationEntityID = objExcel.Cells(strRow, 6).Value MobileAE = objExcel.Cells(strRow, 7).Value NotificationXML = objExcel.Cells(strRow, 8).Value PreFetch = objExcel.Cells(strRow, 9).Value PreFetchSuffix = objExcel.Cells(strRow, 10).Value strRow = strRow + 1 set objRecordSet2=objConnection2.execute(strSQLInsertString) loop objconnection2.close set objConnection2 = Nothing objExcel.Quit 

问题是你的代码是做什么的

 generate sql command with empty values do until end retrieve values from excel execute sql command with empty values loop 

而它应该做的是

 do until end retrieve values from excel generate the new sql command from the retrieved values execute the new generated sql command loop