一个sql问题

amartapple 2003-08-31 01:04:05
access数据库中一个字段为 日期/时间 类型

sql语句为:
DateTime TodayDate = DateTime.Now.Date;
select id,name from person where brith=TodayDate order by brith desc"

编译通过,运行出现运行时错误
...全文
25 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
amartapple 2003-09-02
  • 打赏
  • 举报
回复
问题解决,谢谢大家
tianxia1 2003-09-02
  • 打赏
  • 举报
回复
String TodayDate = DateTime.Now.Date.ToShortDateString();
String strSql = "select id,name from person where brith=#"+TodayDate+"# order by brith desc"
tianxia1 2003-09-02
  • 打赏
  • 举报
回复
DateTime TodayDate = DateTime.Now.Date.ToShortDateString();
String strSql = "select id,name from person where brith=#"+TodayDate+"# order by brith desc"
wueg2003 2003-09-02
  • 打赏
  • 举报
回复
brith=TodayDate 出错啦
amartapple 2003-09-01
  • 打赏
  • 举报
回复
数据库中只有日期,没有时间
请写出sql语句,我试验一下
canyqf 2003-09-01
  • 打赏
  • 举报
回复
access里面好像日期型的要用#代替'
clzhx 2003-09-01
  • 打赏
  • 举报
回复
同意 lamcoo(烟虫)
kuangren 2003-09-01
  • 打赏
  • 举报
回复
时间用''引着~
amartapple 2003-09-01
  • 打赏
  • 举报
回复
是呀,数据库中是时间/日期型,比如:2002-5-26
这中类型怎么在sql中用
nedvedlh 2003-08-31
  • 打赏
  • 举报
回复
时不是你的字段类型不一致啊!本身语句没有问题!
lamcoo 2003-08-31
  • 打赏
  • 举报
回复
键盘有点坏,上面的29:59:59 应为: 23:59:59
lamcoo 2003-08-31
  • 打赏
  • 举报
回复
string strStart = DateTime.Now.toString("yyyyMMdd ")+"00:00:00";
string strEnd = DateTime.Now.toString("yyyyMMdd ")+"29:59:59";

execSql("select id,name from person where brith>'"+strStart+"' and brith<'"+strEnd+"' order by brith desc")
lamcoo 2003-08-31
  • 打赏
  • 举报
回复
select id,name from person where brith=Convert(datetime,TodayDate) order by brith desc

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧