以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  怎样用表达式从身份证列中实现“性别”和“年龄”  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=100305)

--  作者:dsj001
--  发布时间:2017/5/9 12:29:00
--  怎样用表达式从身份证列中实现“性别”和“年龄”
身份证列有数字,怎样自动生成性别和年龄,请老师给个解答。
--  作者:wyz20130512
--  发布时间:2017/5/9 12:54:00
--  
DataColChanged事件代码

Select Case e.DataCol.Name
    Case "身份证"
        e.DataRow("性别") = ReadSex(e.NewValue)
        Dim sp As TimeSpan = Today() - ReadBirthDay(e.NewValue)
        e.DataRow("年龄") = sp.TotalDays / 365
End Select

--  作者:有点色
--  发布时间:2017/5/9 14:21:00
--  

DataColChanged事件

 

Select Case e.DataCol.Name
    Case "身份证号"
        If e.DataRow.IsNull("身份证号") Then  \'身份证号码是否为空
            e.DataRow("出生日期") = Nothing  \'如果为空,则清除出生日期
            e.DataRow("性别") = Nothing  \'如果为空,则清除出生日期
            e.DataRow("年龄") = Nothing \'如果为空,则清除年龄
        Else
            \'否则从身份证号码列中提取出生日期
            e.DataRow("出生日期") = ReadBirthday(e.DataRow("身份证号"))
            e.DataRow("性别") = ReadSex(e.DataRow("身份证号"))
            Dim d As Date = ReadBirthday(e.DataRow("身份证号"))
            Dim y As Integer = d.year
            If format(d, "MMdd") <= Format(Date.Today, "MMdd") Then
                e.DataRow("年龄") = Date.Today.Year - y
            Else
                e.DataRow("年龄") = Date.Today.Year - y -1
            End If
        End If
End Select

[此贴子已经被作者于2017/5/10 9:12:59编辑过]

--  作者:dsj001
--  发布时间:2017/5/10 8:33:00
--  
重置列后显示Exception has been thrown by the target of an invocation.是什么意识?只有第一行出来“出生日期”“性别”年龄没有,其它行都没有数据。
--  作者:有点色
--  发布时间:2017/5/10 9:14:00
--  

你的列名叫什么,要写成【身份证号】,3楼的代码写错了

 

Select Case e.DataCol.Name
    Case "身份证号"
        If e.DataRow.IsNull("身份证号") Then  \'身份证号码是否为空
            e.DataRow("出生日期") = Nothing  \'如果为空,则清除出生日期
            e.DataRow("性别") = Nothing  \'如果为空,则清除出生日期
            e.DataRow("年龄") = Nothing \'如果为空,则清除年龄
        Else
            \'否则从身份证号码列中提取出生日期
            e.DataRow("出生日期") = ReadBirthday(e.DataRow("身份证号"))
            e.DataRow("性别") = ReadSex(e.DataRow("身份证号"))
            Dim d As Date = ReadBirthday(e.DataRow("身份证号"))
            Dim y As Integer = d.year
            If format(d, "MMdd") <= Format(Date.Today, "MMdd") Then
                e.DataRow("年龄") = Date.Today.Year - y
            Else
                e.DataRow("年龄") = Date.Today.Year - y -1
            End If
        End If
End Select