Sql server 根据函数返回的数量在表中插入一行
我有一个返回计数的函数。使用这个返回的计数,我想为函数返回的每个数量在SQL表中插入一个新行 以下是我开始的示例:Sql server 根据函数返回的数量在表中插入一行,sql-server,vb.net,tsql,Sql Server,Vb.net,Tsql,我有一个返回计数的函数。使用这个返回的计数,我想为函数返回的每个数量在SQL表中插入一个新行 以下是我开始的示例: compcount = ems.getparentcountfromorder(row("ordernumber")) Dim count As Object = compcount For Each i As Object In count connection.executesql("INSERT INTO composite_pick_ID (parentpr
compcount = ems.getparentcountfromorder(row("ordernumber"))
Dim count As Object = compcount
For Each i As Object In count
connection.executesql("INSERT INTO composite_pick_ID (parentprodid, ordernumber) VALUES('" & row("productid") & "','" & row("ordernumber") & "')")
count = count - 1
Next
我希望我的最终结果是这样的:
,则我希望在复合拾取ID中插入两行如果count=2
ems.getparentcountfromorder(row(“ordernumber”))
是为SQL返回而编码的,那么当SQL作为查询结果返回Null时,维度count
将作为可空整数来处理
Dim count as Nullable(of Integer) = ems.getparentcountfromorder(row("ordernumber"))
'or in shorthand
Dim count as integer? = ems.getparentcountfromorder(row("ordernumber"))
If count.HasValue then
For i as Integer = 1 to count
connection.executesql('my insert statement')
Next
End if
更多关于VB中可空类型的信息,请点击此处:现在发生了什么?为什么要把所有东西都转换成对象?compcount的类型是什么?我们将compcount设置为整数,至于将其设置为对象,当它是整数时,我无法遍历count,并且不知道如何执行。只需
将I=0设置为compcount-1
并将compcount设置为整数