以文本方式查看主题

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

--  作者:xl
--  发布时间:2009/12/24 9:59:00
--  找不到“清零”贴子
我记得论坛上贺老师“清零”贴子(非表达式型或事件型),找不到了。
[此贴子已经被作者于2009-12-24 11:22:22编辑过]

--  作者:yangming
--  发布时间:2009/12/24 10:39:00
--  
If e.DataCol.IsNumeric Then
    If
e.NewValue = 0 Then
        e.NewValue =
Nothing
    End
if
End
If

放在DataColChanging事件中

--  作者:xl
--  发布时间:2009/12/24 11:14:00
--  

我这样设计,行吗?
For Each dr1 As DataRow In DataTables("表A").DataRows
    For Each dc As DataCol In DataTables("表A").DataCols
        if  dr1(dc)=0 then
            Dr1(dc)=nothing
        end if
    Next
Next


--  作者:czy
--  发布时间:2009/12/24 11:15:00
--  
以下是引用xl在2009-12-24 11:14:00的发言:

我这样设计,行吗?
For Each dr1 As DataRow In DataTables("表A").DataRows
    For Each dc As DataCol In DataTables("表A").DataCols
        if  dr1(dc)=0 then
            Dr1(dc)=nothing
        end if
    Next
Next


不行,最起码你得用IsNumeric判断某列是不是数值型才可以。


--  作者:xl
--  发布时间:2009/12/24 11:19:00
--  
有问题,只有“0”是“双精度小数”时才能清零,若为其它类型如字符型怎么清零呢?
--  作者:yangming
--  发布时间:2009/12/24 11:22:00
--  
字符型只能是为空啊
--  作者:czy
--  发布时间:2009/12/24 11:50:00
--  
以下是引用xl在2009-12-24 11:19:00的发言:
有问题,只有“0”是“双精度小数”时才能清零,若为其它类型如字符型怎么清零呢?


那你就多加一个判断。


--  作者:czy
--  发布时间:2009/12/24 11:51:00
--  
这样应该也行吧?

For Each dr1 As DataRow In DataTables("表A").DataRows
    For Each dc As DataCol In DataTables("表A").DataCols
        If dc.IsNumeric Then
            if  dr1(dc) =0 then
                Dr1(dc)=nothing
            end if
        End If
        If dc.IsNumeric = False
            if  dr1(dc) = "0" then
                Dr1(dc)=nothing
            End If
        End If
    Next
Next

--  作者:xl
--  发布时间:2009/12/24 13:50:00
--  
以下是引用czy在2009-12-24 11:51:00的发言:
这样应该也行吧?

For Each dr1 As DataRow In DataTables("表A").DataRows
    For Each dc As DataCol In DataTables("表A").DataCols
        If dc.IsNumeric Then
            if  dr1(dc) =0 then
                Dr1(dc)=nothing
            end if
        End If
        If dc.IsNumeric = False
            if  dr1(dc) = "0" then
                Dr1(dc)=nothing
            End If
        End If
    Next
Next

行。同样是“0”,也必须注意数值型和字符型之分。


--  作者:xl
--  发布时间:2009/12/24 13:53:00
--  
谢谢两位版主!清零目目前有四种方法供选择(以上两种,下列还有两种):
http://www.foxtable.com/dispbbs.asp?BoardID=2&ID=784&replyID=&skin=1