使用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
- Excel VBA – 激活的工作表上的下一行错误
- 如何在MS Excel单元格中使用C#添加数字validation
- 通过导出Pythonpandas数据框replace部分工作表
- 遍历范围并find空单元格
- 最快的方法来通过SQL数据库列对Excel列循环 – C#
- 使用Excel处理大量的输出数据:是Excel数据库交互问题的正确解决scheme吗?
- 在用户窗体上使用一个button来获得一个variables并继续子
- 将date导出到Csv并告诉excel的格式
- 有人可以提供代码/逻辑来检索excel(.xlsx)数据,比如“”driver.findElement(By.id(“”))。sendkeys(getExceldata(row,column));“