送分了。。。。请看过来(50分)

  • 主题发起人 wldandan
  • 开始时间
W

wldandan

Unregistered / Unconfirmed
GUEST, unregistred user!
我用的是access的数据库,现在想查询一下某一月份的总产量,
产量 日期
100 2002-1-1
200 2002-1-3
300 2002-2-1
100 2002-3-4
我想输入edit1为年份,edit2为月份,
怎么在dbgrid中最后显示某年某月的总产量;
小弟刚入门,请多多执教
 
with dbgrid do
begin
sql='select sum(产量) from tablename where #2002-1-1<日期<#2002-2-1#';
adoquery.execSQL;
Cells[0,RowCount-1] := 结果;
end;
 
我把上面的代码稍微改一下
querySTime: string;
queryETime: string;
with dbgrid1 do
begin
querySTime:=Edit1.text+'-'+Edit2.text+'-01';
queryETime:=Edit1.text+'-'+Edit2.text+'-31';
sql:='select sum(产量) as mysum from tablename where 日期 between #'+querySTime+'#';
sql:=sql+' and #'+queryETime+'#';
adoquery.execSQL;
Cells[0,RowCount-1] := adoquery.FieldByName('mysum').asString;
end;
 
我是这样写的,可是怎么报错说类型不匹配。。。。

year:=edit1.text;
month:=ComboBox1.Text;
month:=copy(month,1,1);
time:=year+'-'+month;
time1:=time+'-'+'1';
time2:=time+'-'+'31';
query1.Close;
query1.SQL.Clear;
query1.SQL.Add('select sum(id) from 地址 where 日期>=:time11 and 日期<=:time22');
query1.Params[0].Value:=time1;
query1.Params[1].Value:=time2;
query1.Open;
 
顶部