在表的datacolchanged事件中加以下代码:
If e.DataCol.Name = "身份证号" And e.DataRow("身份证号") IsNot Nothing Then Dim dt1 As Date dt1=Date.today() Dim dt2 As Date=e.DataRow("出生日期") Dim y,m,d As Integer DateYMD(dt1,dt2,y,m,d) If m*d<>0 Then y=y+1 End If e.DataRow("年龄")=yEnd If