以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  自定义函数问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=132644)

--  作者:whoisvinci
--  发布时间:2019/3/26 15:51:00
--  自定义函数问题

\'函数("Add_ID","编号列名","编号字符")

Dim ID_ColName As String = Args(0)
Dim ID_Symbol As String = Args(1)
Dim cmd As New SQLCommand
Dim dt As Date
cmd.C
cmd.CommandText = "Select GetDate()" \'从远程数据库获取日期信息
dt = cmd.ExecuteScalar()
CurrentTable.Current("日期") = dt
Dim d As Date = CurrentTable.Current("日期")
Dim y As Integer = d.Year
Dim m As Integer = d.Month
Dim Days As Integer = Date.DaysInMonth(y,m)
Dim fd As Date = New Date(y,m,1) \'获得该月的第一天
Dim ld As Date = New Date(y,m,Days) \'获得该月的最后一天
Dim bh As String = ID_Symbol & Format(d,"yyMM") \'生成ID_ColName的前6位,2位字符,2位年,2位月.
CurrentTable.Current.Save \'***必须在sqlcompute前先保存,才能获得当前行的真实的_identify值***
If CurrentTable.Current(ID_ColName).StartsWith(bh) = False \'如果ID_ColName的前6位不符
    Dim max As String
    Dim idx As Integer 
    max = CurrentTable.DataTable.sqlCompute("Max(CurrentTable.Cols(ID_ColName).Name)","[日期] >= \'" & fd & "\' And [日期] < \'" & ld.AddDays(1) & "\'And [_Identify] <> " & CurrentTable.Current("_Identify")) \'取得该月的最大ID_ColName
    If max > "" Then \'如果存在最大ID_ColName
        idx = CInt(max.Substring(6,4)) + 1 \'获得最大ID_ColName的后四位顺序号,并加1
    Else
        idx = 1 \'否则顺序号等于1
    End If
    CurrentTable.Current(ID_ColName) = bh & Format(idx,"0000")
    CurrentTable.Current.save  
End If

 

 


图片点击可在新窗口打开查看此主题相关图片如下:qq拼音截图未命名.jpg
图片点击可在新窗口打开查看

 

 

建立函数后调用,弹出错误,应该是Max函数的格式问题,但不知道怎么解决


--  作者:有点甜
--  发布时间:2019/3/26 16:00:00
--  

sqlCompute("Max(CurrentTable.Cols(ID_ColName).Name)"

 

改成

 

sqlCompute("Max(" & CurrentTable.Cols(ID_ColName).Name & ")"