【发布时间】:2020-06-17 06:44:55
【问题描述】:
所以按照我的循环表的代码,连接到 sql server 并发送表的数据,我还有一个小约束: 我逐行、逐个单元地发送 5400 行和 13 列数据(实际上并没有那么慢!)但我需要在某个单元格上设置条件:如果我已经发送了单元格的内容(例如:客户端号码已经发送到数据库中)我不想插入两次,所以转到下一次迭代。 这是我的循环的简化版本:
nrow = 1
While My_range.Offset(nrow).Value <> "" 'continue if cell's not empty
'connect to the db and create a command that send the data
Set mobjCmd = New ADODB.Command
With mobjCmd
.ActiveConnection = mobjConn
.CommandText = "INSERT_PRODUCT"
.CommandType = adCmdStoredProc
.CommandTimeout = 0
'append the cell of the second row, first column in the db in the Client_id column in my SQL table
.Parameters.Append .CreateParameter("@Client_id", adChar, adParamInput, 255, Worksheets("My_Sheet").Range("A1").Offset(nrow, 0).Value)
.Execute
Wend
基本上我想过这样的事情:
If ... then GoTo NextIteration
End if
NextIteration: my_next_iteration
但是如何设置 i/o "..." 以便如果它看到它已经发送的 client_id 就进入下一个迭代。
提前感谢您的帮助!
【问题讨论】:
标签: excel vba while-loop exists goto