以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]自动编号问题  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=56439)

--  作者:jygyyl
--  发布时间:2014/9/5 10:21:00
--  [求助]自动编号问题
各位老师,早上好!
      请教一下自动编号问题:我的数据表是外部数据,用Compute计算最大编号时,如果没有加载数据则编号重复从1开始。改用SQLCompute,提示如下错误:

.NET Framework 版本:2.0.50727.4984

Foxtable 版本:2014.8.6.1

错误所在事件:

详细错误信息:

\'.01\' 附近有语法错误。

不明白错在什么地方,代码如下,请老师指正!


Select e.DataCol.Name

    Case "GB311","GB402"

        If e.DataRow.IsNull("GB311") OrElse e.DataRow.IsNull("GB402") Then

            e.DataRow("编号") = Nothing

        Else

            Dim d As Date = e.DataRow("GB311")

            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,1,1) \'获得该月的第一天

            Dim ld As Date = New Date(y,12,31) \'获得该月的最后一天

            Dim bh As String = e.DataRow("GB402") & "-" & Format(d,"yyyy") & "-" \'生成编号的前缀

            If e.DataRow("编号").StartsWith(bh) = False \'如果单据编号前缀不符

                Dim max As String

                Dim idx As Integer

                Dim flt As String

                flt = "GB402 = \'"& e.DataRow("GB402") & "\' And GB311 >= #" & fd & "# And GB311 <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")

                max = e.DataTable.SQLCompute("Max(编号)",flt) \'取得该月的相同工程代码的最大单据编号

                If max > "" Then \'如果存在最大单据编号

                    idx = CInt(max.Substring(15,4)) + 1 \'获得最大单据编号的后四位顺序号,并加1

                Else

                    idx = 1 \'否则顺序号等于1

                End If

                e.DataRow("编号") = bh & Format(idx,"0000")

            End If

        End If

End Select


--  作者:有点甜
--  发布时间:2014/9/5 10:27:00
--  

 你的数据库是sqlserver?

 

 那你要把#改成\'

 

 flt = "GB402 = \'"& e.DataRow("GB402") & "\' And GB311 >= \'" & fd & "\' And GB311 <= \'" & ld & "\' And [_Identify] <> " & e.DataRow("_Identify")


--  作者:jygyyl
--  发布时间:2014/9/5 10:32:00
--  回复:(有点甜) 你的数据库是sqlserver?&nb...
谢谢甜老师!不好意思,犯了一个常识性错误!