以文本方式查看主题

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

--  作者:riyuan
--  发布时间:2014/8/21 11:36:00
--  [求助]
请教表中根据出生日期或身份证号筛选出年龄在某一范围内的数据
我的语句要出错
不知道是什么原因
Dim cmd As new SQLCommand
cmd.C
cmd.CommandText="select * from {hkxx} where 出生日期>=60 and 出生日期<=70

--  作者:Bin
--  发布时间:2014/8/21 11:40:00
--  
出生日期  是日期类型吧, 你和数值 60 怎么对比?

应该先计算出60岁的出生年月

Dim d1 As Date = Date.Today.AddYears(60)
dim d2 as date  = Date.Today.AddYears(70)

cmd.CommandText="select * from {hkxx} where 出生日期>=#" & d1 & "# and 出生日期<="#" & d2 & "#"


--  作者:riyuan
--  发布时间:2014/8/21 11:50:00
--  
感觉没有对哟。
Dim d1 As Date = Date.Today.AddYears(60)
dim d2 as date  = Date.Today.AddYears(70)
这两句话是在的日期上加上60年和70年的嘛


--  作者:有点甜
--  发布时间:2014/8/21 11:51:00
--  
 你的数据库,是什么数据库?sqlserver还是Access?
--  作者:有点甜
--  发布时间:2014/8/21 11:53:00
--  

如果是Access数据源

 

Dim d1 As Date = Date.Today.AddYears(-60)
dim d2 as date  = Date.Today.AddYears(-70)

cmd.CommandText="select * from {hkxx} where 出生日期<=#" & d1 & "# and 出生日期>=#" & d2 & "#"
[此贴子已经被作者于2014-8-21 11:54:18编辑过]

--  作者:有点甜
--  发布时间:2014/8/21 11:54:00
--  

如果是sqlserver数据源

 

Dim d1 As Date = Date.Today.AddYears(-60)
dim d2 as date  = Date.Today.AddYears(-70)

cmd.CommandText="select * from {hkxx} where 出生日期<=\'" & d1 & "\' and 出生日期>=\'" & d2 & "\'"
[此贴子已经被作者于2014-8-21 11:54:32编辑过]