以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 如何根据参数个数动态增加? (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=192138) |
-- 作者:HappyFt -- 发布时间:2024/5/30 22:46:00 -- 如何根据参数个数动态增加? dim cols as string = "来源单号,产品编码" Dim cs() As String = cols.split(",") \'拆分字符串为数组 dim i2 as integer = cs.length \'如果是2个参数就写2个问号,3个就写3个问号? cmd.CommandText = "Select 需求数量,累计数量 from dbo."
& ufnName & "(?,?)" For i As Integer = 0 To cs.Length - 1 \'动态传入参数 cmd.Parameters.Add("@" & cs(i), dr(cs(i))) Next 如上面函数动态传参时如何实现红色部份变动? 谢谢! |
-- 作者:有点蓝 -- 发布时间:2024/5/30 23:33:00 -- dim cols as string = "来源单号,产品编码" Dim cs() As String = cols.split(",") \'拆分字符串为数组 For i As Integer = 0 To cs.Length - 1 \'动态传入参数 cmd.Parameters.Add("@" & cs(i), dr(cs(i))) s = s & "?," Next cmd.CommandText = "Select 需求数量,累计数量 from dbo." & ufnName & "(" & s.trim(",") & ")"
|
-- 作者:HappyFt -- 发布时间:2024/5/31 9:52:00 -- 原来以为cmd.Parameters.Add只能放在select函数的后面,可以放在前面拼接就简单了,谢谢! |