返回信息流我在MFC中用ADO访问数据库Access2007
写了一个sql语句
CString strName,strSQL1,strIn,strAge;
strName=m_list1.GetItemText(iIndex,0);
strIn=m_list1.GetItemText(iIndex,3);
strSQL1.Format("select * from Car_Management where Number='"+strName+"' and CheckIn>='"+strIn+"'");
Car_Management 为表名
如果只用Number='"+strName+"'一个条件,运行就没问题。Number在数据表中是文本类型
但是加上CheckIn>='"+strIn+"'运行就出错,CheckIn在表是 时间/日期类型
ps:: 还这样写过
strSQL1.Format("select * from Car_Management where Number='%s' and CheckIn='%s'"); 结果同上。问题出在CheckIn='%s',可能写错了,但是不知道怎么改
求大牛指教
这是一条镜像帖。来源:北邮人论坛 / cpp / #40716同步于 2010/6/24
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
请教大牛关于ado访问Access2007
yaxing1984
2010/6/24镜像同步5 回复
订阅后,新回复会通过你的通知中心匿名送达。
5 条回复
where Number='"+strName+"' and CheckIn>='"+strIn+"'"
里面的引號對嗎
不是大牛 隨便一水
【 在 yaxing1984 的大作中提到: 】
: 我在MFC中用ADO访问数据库Access2007
: 写了一个sql语句
: CString strName,strSQL1,strIn,strAge;
: ...................
【 在 guo 的大作中提到: 】
: where Number='"+strName+"' and CheckIn>='"+strIn+"'"
: 里面的引號對嗎
: 不是大牛 隨便一水
: ...................
CheckIn>='"+strIn+"'
里面是双引号,外面是单引号
CheckIn的数据类型不是Datatime么?为什么要加单引号?
这不是变成了:
select * from Car_Management where Number='str1' and CheckIn='date1'
了么
把CheckIn等号后面的单引号去掉吧
遇到这种问题,应该先用messagebox或者断电得到存放sql语句字符串变量的具体内容,然后拿到数据库里执行一遍就ok了。
access2007就更方便了,打开mdb文件,新建一个查询就行了