以文本方式查看主题

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

--  作者:aduydgd
--  发布时间:2014/5/3 21:51:00
--  [求助]获取为空字段的列名称

高手好,做了个提示,可以获取到位空的字段在第几行,还想获取为空字段的列名称,一直没有搞定,高手帮忙一下,

这是我之前的

 

MessageBox.Show("第 " & r.Index + 1 & " 行" 这里加代码"不允许为空,请检查数据!","提示")

 

谢谢!


--  作者:y2287958
--  发布时间:2014/5/3 21:54:00
--  
看看这里有没有启发?
--  作者:aduydgd
--  发布时间:2014/5/3 22:16:00
--  
没有
--  作者:y2287958
--  发布时间:2014/5/3 22:22:00
--  
上个例子和详细说明吧
--  作者:lsy
--  发布时间:2014/5/4 7:36:00
--  
Dim s As String
Dim cs As String
For Each r As Row In Tables("表A").Rows
    cs = ""
    For Each c As String In "日期|序号|名称".Split("|")
        If r.IsNull(c) Then
            cs + = "【" & c & "】列"
        End If
    Next
    If cs > "" Then
        s + = "第 " & r.Index + 1 & " 行 " & cs & Vbcrlf
    End If
Next
MessageBox.Show(s,"以下各行的几个列值不能为空")

--  作者:aduydgd
--  发布时间:2014/5/7 11:58:00
--  
以下是引用lsy在2014-5-4 7:36:00的发言:
Dim s As String
Dim cs As String
For Each r As Row In Tables("表A").Rows
    cs = ""
    For Each c As String In "日期|序号|名称".Split("|")
        If r.IsNull(c) Then
            cs + = "【" & c & "】列"
        End If
    Next
    If cs > "" Then
        s + = "第 " & r.Index + 1 & " 行 " & cs & Vbcrlf
    End If
Next
MessageBox.Show(s,"以下各行的几个列值不能为空")

我的字段都是英文,提示的内容人家看不懂啊,怎么让提示中文?


--  作者:有点甜
--  发布时间:2014/5/7 12:54:00
--  
以下是引用aduydgd在2014-5-7 11:58:00的发言:

我的字段都是英文,提示的内容人家看不懂啊,怎么让提示中文?

 

 

Dim s As String
Dim cs As String
For Each r As Row In Tables("表A").Rows
    cs = ""

    Dim arycs() As String = "date|num|name".Split("|")

    Dim arytips() As String = "日期|序号|名称".Split("|")
    For i As integer = 0 to arycs.Length - 1

        If r.IsNull(arycs(i)) Then
            cs + = "【" & arytips(i) & "】列"
        End If
    Next
    If cs > "" Then
        s + = "第 " & r.Index + 1 & " 行 " & cs & Vbcrlf
    End If
Next
MessageBox.Show(s,"以下各行的几个列值不能为空")

[此贴子已经被作者于2014-5-7 12:54:18编辑过]

--  作者:aduydgd
--  发布时间:2014/5/10 9:44:00
--  
大哥,这个提示,有空的记录会提示,提示完成后还会进行下面的操作,没有空记录时,也是会提示,只不过提示框里面没有提示内容,提示完成后也同样会执行下面的操作,这个怎么改改,提示存在空数据后,不能保存,如果不存在空数据,就直接保存就可以了
--  作者:Bin
--  发布时间:2014/5/10 9:50:00
--  
只是想提示YOU空值的列,不能保存的话.无须这么麻烦

BeforeSaveDataRow中

For Each dc As DataCol In e.DataTable.DataCols
    If e.DataRow.IsNull(dc.name) Then
       MessageBox.show(dc.name & "不能为空!")
       e.Cancel=True
        Exit For
    End If
Next

如果列名是英文,列标题是中文,那么提示用

For Each dc As DataCol In e.DataTable.DataCols
    If e.DataRow.IsNull(dc.name) Then
       MessageBox.show(dc.Caption & "不能为空!")
       e.Cancel=True
        Exit For
    End If
Next

--  作者:aduydgd
--  发布时间:2014/5/10 11:49:00
--  
以下是引用Bin在2014-5-10 9:50:00的发言:
只是想提示YOU空值的列,不能保存的话.无须这么麻烦

BeforeSaveDataRow中

For Each dc As DataCol In e.DataTable.DataCols
    If e.DataRow.IsNull(dc.name) Then
       MessageBox.show(dc.name & "不能为空!")
       e.Cancel=True
        Exit For
    End If
Next

如果列名是英文,列标题是中文,那么提示用

For Each dc As DataCol In e.DataTable.DataCols
    If e.DataRow.IsNull(dc.name) Then
       MessageBox.show(dc.Caption & "不能为空!")
       e.Cancel=True
        Exit For
    End If
Next

我检测空值字段不是全部的,是个别几个,要提示出哪一行和空值的列,有空值不能保存,没有空值就保存