我已将SQL Insert语句包装在下面的Do While循环中,但它只是将范围中的最后一行插入到SQL表中。我想要实现的是将每行复制到表中。所以在excel的示例数据中我有8行,我需要将所有8行复制到我的SQL表中。我想,也许我的循环错了,或者只是需要调整,但我正在努力
Do While Sheets("Exposure").Range("B14").Offset(i, 0).Value <> ""
j = i + 1
' Compose the INSERT statement.
stSQL = "INSERT INTO AH_Exposure " & _
"(Contract_ID, Location_ID, Country, State, Death_GrpVol, Death_GrpLives, Death_IndVol, Death_IndLives, Disability_GrpVol, Disability_GrpLives, Disability_IndVol, Disability_IndLives) " & _
" VALUES (" & _
"'" & Sheets("Exposure").Range("B14").Offset(i, 0).Value & "', " & _
"'" & j & "', " & _
"'" & Sheets("Exposure").Range("C14").Offset(i, 0).Value & "', " & _
"'" & Sheets("Exposure").Range("D14").Offset(i, 0).Value & "', " & _
"'" & Sheets("Exposure").Range("E14").Offset(i, 0).Value & "', " & _
"'" & Sheets("Exposure").Range("F14").Offset(i, 0).Value & "', " & _
"'" & Sheets("Exposure").Range("G14").Offset(i, 0).Value & "', " & _
"'" & Sheets("Exposure").Range("H14").Offset(i, 0).Value & "', " & _
"'" & Sheets("Exposure").Range("I14").Offset(i, 0).Value & "', " & _
"'" & Sheets("Exposure").Range("J14").Offset(i, 0).Value & "', " & _
"'" & Sheets("Exposure").Range("K14").Offset(i, 0).Value & "', " & _
"'" & Sheets("Exposure").Range("L14").Offset(i, 0).Value & "'" & _
")"
i = i + 1
Loop
提前致谢
答案 0 :(得分:1)
您正在编写语句,但循环中没有代码可以实际执行它。因此它只是stSQL中使用的最后一个值