以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 自定义函数中使用ExecuteReader得到DataTable,但引用函数时提示:不存在名为“dt”的DataTable (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=28604) |
-- 作者:jinruan -- 发布时间:2013/2/4 21:58:00 -- 自定义函数中使用ExecuteReader得到DataTable,但引用函数时提示:不存在名为“dt”的DataTable Dim no As String \'单据编码 Dim nm As String = Args(0) \'单据类型 Dim cmd1 As New SQLCommand Dim cmd2 As New SQLCommand cmd1.C cmd2.C Dim Key As Integer cmd1.commandText = "Select [顺序号] From [ss_num] Where [单据类型] = \'" & nm & "\'" Do Key = cmd1.ExecuteScalar() \'从后台获得顺序号 cmd2.commandText = "Update [ss_num] Set [顺序号] = " & (Key + 1) & " Where [顺序号] = " & Key & " And [单据类型] = \'" & nm & "\'" If cmd2.ExecuteNonQuery() > 0 Then \'更新顺序号 Exit Do \'更新成功则退出循环 End If Loop Dim cmd4 As New SQLCommand Dim dt As DataTable cmd4.C cmd4.CommandText = "Select * From [ss_num] Where [单据类型] = \'" & nm & "\'" dt = cmd4.ExecuteReader() Dim dr As DataRow dr = DataTables("dt").Find("[单据类型] = \'" & nm & "\'") If dr IsNot Nothing Then \'如果找到的话 Dim s As New String("0", dr("序号位数")) no = Format(Args(2),dr("编码规则")) & "-" & Format(Key,s) \'生成编码 End If Return no
[此贴子已经被作者于2013-2-5 8:39:34编辑过]
|
-- 作者:jinruan -- 发布时间:2013/2/5 8:39:00 -- 可以了!感谢! |