以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 在出生日期列查询过生日的人 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=16927) |
||||
-- 作者:sunliqiang -- 发布时间:2012/2/27 21:33:00 -- 在出生日期列查询过生日的人 From {居民信息表} Where [出生日期]=today.month and [出生日期]=today.day 上面的表达式怎么不对 |
||||
-- 作者:blackzhu -- 发布时间:2012/2/28 7:58:00 -- 这样的吧:From {居民信息表} Where [出生日期]=# "& today.month & "# and [出生日期]=#" & today.day & "#" |
||||
-- 作者:狐狸爸爸 -- 发布时间:2012/2/28 8:02:00 -- 你可以参考一下这个:
http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=11929&skin=0
|
||||
-- 作者:狐狸爸爸 -- 发布时间:2012/2/28 11:55:00 -- 假定有个员工表,有姓名和出生日期列,希望能够筛选出今天生日的行,代码为:
Dim nms As StringFor Each dr As DataRow In DataTables("员工").DataRows Dim dt As Date = dr("出生日期") If dt.Month = Date.Today.Month AndAlso Date.Today.Day Then nms = nms & ",\'" & dr("姓名") & "\'" End If Next If nms > "" Then nms = nms.Trim(",") Tables("员工").filter = "[姓名] In (" & nms &")" End If
如果希望筛选出未来七天内生日的员工,代码为:
Dim nms As StringFor Each dr As DataRow In DataTables("员工").DataRows Dim dt As Date = dr("出生日期") dt = New Date(Date.Today.Year,dt.Month,dt.Day) If dt >= Date.Today AndAlso dt < Date.Today.AddDays(6) Then nms = nms & ",\'" & dr("姓名") & "\'" End If Next If nms > "" Then nms = nms.Trim(",") Tables("员工").filter = "[姓名] In (" & nms &")" End If
上面的代码有漏洞,假定有两个张三,其中一个张三今天生日,那么执行上述代码之后,两个张三都会显示出来,尽管另一个张三并不是今天生日。 要解决这个问题,可以参考下面的代码,同样以筛选出今天生日的员工为例:
Dim ids As StringFor Each dr As DataRow In DataTables("员工").DataRows Dim dt As Date = dr("出生日期") dt = New Date(Date.Today.Year,dt.Month,dt.Day) If dt >= Date.Today AndAlso dt < Date.Today.AddDays(6) Then ids = ids & "," & dr("_Identify") End If Next If ids > "" Then ids = ids.Trim(",") Tables("员工").filter = "[_Identify] In (" & ids &")" End If
由于每一行的_Identify列的内容都是不同的,同名带来的问题不复存在。 提示: 如果希望打开项目后,能自动筛选出当天生日的员工,可以将上面的代码设置在AfterOpenProject事件中。 |
||||
-- 作者:sunliqiang -- 发布时间:2012/3/6 9:36:00 -- 我要生成一个查询表,列出今天过生日人的信息。使用了表达式总是错误,求助????? From {居民信息表} Where [出生日期]=# "& today.month & "# and [出生日期]=#" & today.day & "# 说语法错误,反复修改不知道那错了????/ |
||||
-- 作者:狐狸爸爸 -- 发布时间:2012/3/6 9:51:00 -- From {居民信息表} Where Month([出生日期]) = "& Date.Today.Month & " and Day([出生日期]) =" & Date.Today.Day |
||||
-- 作者:sunliqiang -- 发布时间:2012/3/6 10:22:00 -- 老师,生成的为空记录。 {居民信息表} 里面有出生日期有今天的记录啊???、 |
||||
-- 作者:狐狸爸爸 -- 发布时间:2012/3/6 10:29:00 -- 我测试征程,记得你输入的数据,要保存一下才行,因为select 是从后台提取数据。
|
||||
-- 作者:sunliqiang -- 发布时间:2012/3/8 10:47:00 -- 老师,我把我做的程序给您发过去,帮我看一下,为什么做生日查询表生成有错误。生成的为空记录。 {居民信息表} 里面有出生日期有今天的记录啊???我也保存了。
|
||||
-- 作者:sunliqiang -- 发布时间:2012/3/8 10:47:00 -- 密码是648620 |