以文本方式查看主题

-  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=19177)

--  作者:aduydgd
--  发布时间:2012/4/30 13:00:00
--  [求助]帮忙看看代码哪里有错误?

在新增数据时提示错误!

If e.DataCol.Name = "发货日期" Then
    If e.DataRow.IsNull("发货日期") Then
        e.DataRow("编号") = Nothing
    Else
        Dim d As Date = e.DataRow("发货日期")
        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 = Format(d,"yyyyMM") \'生成编号的前6位,4位年,2位月.
        If e.DataRow("编号").StartsWith(bh) = False \'如果编号的前6位不符
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.Compute("Max(编号)","发货日期 >= #" & fd & "# And 发货日期 <= #" & ld & "#") \'取得该月的最大编号
            If max > "" Then \'如果存在最大编号
                idx = CInt(max.Substring(7,3)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("编号") = bh & "-" & Format(idx,"000")
        End If
    End If
End If


--  作者:e-png
--  发布时间:2012/4/30 13:30:00
--  

 

 

如果这是一个新的行,那么[编号]列一般是空的。那么哪来的If e.DataRow("编号").StartsWith(bh) = False 


--  作者:e-png
--  发布时间:2012/4/30 13:44:00
--  

【发货日期 >= #" & fd & "# And  ......】这里 fd 也不是一个日期

 


--  作者:aduydgd
--  发布时间:2012/4/30 14:49:00
--  
那么正确的呢?
--  作者:e-png
--  发布时间:2012/4/30 15:36:00
--  

没有实例,没法给你正确的,我不是大师。就是大师也要看到你的实例啊。


--  作者:布莱克朱
--  发布时间:2012/5/1 9:41:00
--  
代码放在了新增事件里面了?