delphi sql 怎么做?

来源:百度知道 编辑:UC知道 时间:2024/05/21 08:28:53
最近用Delphi sql 做毕业设计,有一个统计做起来有点问题

开始时间 edit1
截止时间 edit2
统计(button)
时间段内建设个数 edit3

edit1,edit2都是用户要输入的时间,,button是统计按纽.
对SQL内容进行统计,希望统计到时间段内建设项目的个数,并将结果显示在edit3中,我用的是ADOQuery,用的SQL语句是
select count(*) as count from tabel where 建设时间>='edit1.text' and 建设时间<'edit2.text'
button(统计)用的语句是
adoquery1.close;
adoquery.sql.clear;
adoquery.sql.add('select * from tabel where 建设时间>='edit1.text' and 建设时间<'edit2.text'
');
adoquery1.open;
Edit3.Text:=IntToStr(adoquery1.RecordCount);
end;
可就是没法显示在edit3中,不知道是哪里出现了问题,希望各位路过的高手帮帮忙,谢谢了~

把sql语句改为
sql:='select * from tabel where 建设时间>=:sj1 and 建设时间<:sj2';
adoquery1.close;
adoquery.sql.clear;
adoquery.sql.add(sql);
adoquery.parement.parementbyname('sj1').value:=edit1.text;
adoquery.parement.parementbyname('sj2').value:=edit2.text;
adoquery.open;
就对了
这样查询出来的行数才是你要的,不然的话,你要读取结果集中的count 字段的值,才是你要的答案

你看你的程序...一个是adoquery.sql.add
adoquery1.open

一个有1,1个没1............

还有,建议用人工断点调试的方法,把
'select * from tabel where 建设时间>='edit1.text' and 建设时间<'edit2.text'
'
这一句赋直到EDIT3中,其他的语句先屏蔽掉.然后运行.然后把EDIT3中显示的SQL语句COPY进查询分析器中执行一下.看看能不能执行.

学不会调试是不会成为一个好的程序员的.