DELPHI+ACCESS
程序如下:
self.adoquery1.close;
self.adoquery1.sql.clear;
self.adoquery1.sql.add('select * yhxx');
self.adoquery1.sql.add('where rq='''+self.label1.caption+'''');
self.qdoquery1.prepear;
self.adoquery1.open;注:'rq'字段为日期/时间类型,短日期类型。
程序如下:
self.adoquery1.close;
self.adoquery1.sql.clear;
self.adoquery1.sql.add('select * yhxx');
self.adoquery1.sql.add('where rq='''+self.label1.caption+'''');
self.qdoquery1.prepear;
self.adoquery1.open;注:'rq'字段为日期/时间类型,短日期类型。
解决方案 »
- 如何不用临时表删除TOP100以外的数据呢?
- 请iflang ,keiy(),wudi_1982 接分(补系统BUG丢的分)
- MSFlexGrid在Delphi中发布问题
- 棘手的问题,只好来请教大家了。
- 关于FireBird的简单问题,急!!!
- 在程序中动态创建的FORM如何正常关闭?
- 我装的delphi6,在编译form时,怎么左上角那个小图标不见了???
- 让男人心动的女人
- 使用TMSCOMM控件時出錯信息:License information for TMSComm not found.You cannot user this Control in design mode.
- 如何动态改变dbctrlgrid中的某一格上的image上的shape的brush的color?
- 关于rxlib 2。75安装的问题?
- 如何判断某字符串中是否包含某字符???在线等,可决给分.
select * from 报告单 where 报告日期=#1979-10-18# 如果是时间
时间里面要用两个:号,
select * from 报告单 where 报告日期=#1979-10-18 16::38::00#
self.adoquery1.sql.add('select * yhxx');
是什么?写错了吧?
self.adoquery1.sql.add('where rq='''+self.label1.caption+'''');
改为
self.adoquery1.sql.add('where rq='#'+self.label1.caption+'#');
因为在Access中日期型可写为#2003-12-17#,而在SQL Server中,
你的语句如果没有语法错误,则可能是正确的。
self.adoquery1.sql.add('where rq='#'+self.label1.caption+'#');
//比较
//转换用SQL函数CONVERT
//三个参数: 1、转换成什么类型的数据和长度
//2、要转换的数据或字段
//3、转换的数据格式self.adoquery1.close;
self.adoquery1.sql.clear;
self.adoquery1.sql.add('SELECT * FROM yhxx');
self.adoquery1.sql.add('WHERE CONVERT(VARCHAR, rq, 120) = ' + #39 +
self.label1.caption + #39);
self.qdoquery1.prepear;
self.adoquery1.open;=================================================================================
//CONVERT(VARCHAR, rq, 120) 是把日期类型字段rq转换成字符串,字符串格式为
//2003-12-17 13:27:14格式的字符串//如果要用到模糊搜索就用
//self.adoquery1.sql.add('WHERE CONVERT(VARCHAR, rq, 120) LIKE ' + #39 + '%' +
// self.label1.caption + '%' + #39);
CONVERT(VARCHAR(10), rq, 120)
self.adoquery1.sql.clear;
self.adoquery1.sql.add('select * yhxx');
self.adoquery1.sql.add('where rq= #'+self.label1.caption+'#');
self.qdoquery1.prepear;
self.adoquery1.open;注:'rq'字段为日期/时间类型,短日期类型
程序如下:
self.adoquery1.close;
self.adoquery1.sql.clear;
self.adoquery1.sql.add('select * from yhxx '); //
self.adoquery1.sql.add(' where rq='''+self.label1.caption+'''');
// 表名(yhxx)和where 应由至少一个空格;
self.qdoquery1.prepear;
self.adoquery1.open;注:'rq'字段为日期/时间类型,短日期类型。
self.adoquery1.sql.clear;
self.adoquery1.sql.add('select * from yhxx');
self.adoquery1.sql.add('where to_char(rq,'+'''yyymmdd'''+')=''''+self.label1.caption+'''');
self.qdoquery1.prepear;
self.adoquery1.open;
或者你用动态sql参数, 就不需要考虑数据库类型的问题。