本人在写一个程序时,使用DBchart控件,有两个单选钮,按第一个执行一条查询,按第二个执行另一条查询,字段不同。每当单独执行,哪个都正确定,但理旦先执行一个,紧接着执行另一个单选钮时,就会提示先执行的查询结果字段找不到,查找了N多天也苦不到原因,请大侠解救!!下面是源码: if radiobutton1.Checked = true then
begin
sqlstring := 'select xm,zjhm,csrq,gjdqdm,count(xm) as crcs from BJ_YW_T_CRJRYDK Where (crrq between ''' + start_date + '''' + ' and ' + '''' + end_date + ''') ' + ' GROUP BY xm, zjhm, csrq, gjdqdm HAVING COUNT(xm) ' + cxtj + cxtextedit1.Text + ' order by crcs desc';
//showmessage(sqlstring);
dbgrid1.Columns[0].Title.caption := '姓 名';
dbgrid1.Columns[0].Width := 300;
dbgrid1.Columns[0].FieldName := 'xm';
dbgrid1.Columns[1].Title.caption := '证件号码';
dbgrid1.Columns[1].Width := 186;
dbgrid1.Columns[1].FieldName := 'zjhm';
dbgrid1.Columns[2].Title.caption := '出生日期';
dbgrid1.Columns[2].Width := 100;
dbgrid1.Columns[2].FieldName := 'csrq';
dbgrid1.Columns[3].Title.caption := '国家代码';
dbgrid1.Columns[3].Width := 100;
dbgrid1.Columns[3].FieldName := 'gjdqdm';
dbgrid1.Columns[4].Title.caption := '出入次数';
dbgrid1.Columns[4].Width := 100;
dbgrid1.Columns[4].FieldName := 'crcs'; with adoquery1 do
begin
Close;
sql.Clear;
sql.Add(sqlstring);
Open;
end;
if adoquery1.RecordCount > 0 then
begin
num := inttostr(adoquery1.RecordCount);
statusbar1.Panels[1].Text := num;
bitbtn3.Enabled := true;
bitbtn6.Enabled := true;
bitbtn1.Enabled := false;
dbgrid1.Columns[0].font.Color := clRed;
dbgrid1.Columns[1].font.Color := clWindowText;
dbgrid1.Columns[2].font.Color := clWindowText;
DBChart1.Title.Text[0] := '出入境人员过境次数统计示意图';
with DBChart1 do
begin
with Series1 do
begin
//Series1.Clear;
//series1.Active := false;
adoquery1.Active := True;
DataSource := adoquery1;
XLabelsSource := 'xm';
YValues.ValueSource := 'crcs';
// series1.Active := true;
end;
end;
end
else
begin
statusbar1.Panels[1].Text := '0';
application.MessageBox('没有数据!', '提示', 64);
end;
end
else if radiobutton2.Checked = true then
begin
sqlstring := 'select hc,jwgjbs,jngjbs,gjdqdm,count(hc) as crcs from BJ_YW_T_CRJJTGJDK Where (crrq between ''' + start_date + '''' + ' and ' + '''' + end_date + ''') ' + ' GROUP BY hc, jwgjbs, jngjbs, gjdqdm HAVING COUNT(hc) ' + cxtj + cxtextedit1.Text + ' order by crcs desc';
dbgrid1.Columns[0].Title.caption := '车辆牌号';
dbgrid1.Columns[0].Width := 200;
dbgrid1.Columns[0].FieldName := 'hc';
dbgrid1.Columns[1].Title.caption := '境外标识';
dbgrid1.Columns[1].Width := 150;
dbgrid1.Columns[1].FieldName := 'jwgjbs';
dbgrid1.Columns[2].Title.caption := '境内标识';
dbgrid1.Columns[2].Width := 150;
dbgrid1.Columns[2].FieldName := 'jngjbs';
dbgrid1.Columns[3].Title.caption := '国家地区';
dbgrid1.Columns[3].Width := 100;
dbgrid1.Columns[3].FieldName := 'gjdqdm';
dbgrid1.Columns[4].Title.caption := '出入次数';
dbgrid1.Columns[4].Width := 100;
dbgrid1.Columns[4].FieldName := 'crcs';
with adoquery1 do
begin
close;
sql.Clear;
sql.Add(sqlstring);
//showmessage(sqlstring);
Open;
end;
if adoquery1.RecordCount > 0 then
begin
num := inttostr(adoquery1.RecordCount);
statusbar1.Panels[1].Text := num;
bitbtn3.Enabled := true;
bitbtn6.Enabled := true;
bitbtn1.Enabled := false;
dbgrid1.Columns[0].font.Color := clRed;
dbgrid1.Columns[1].font.Color := clWindowText;
dbgrid1.Columns[2].font.Color := clWindowText;
DBChart1.Title.Text[0] := '出入境车辆过境次数统计示意图';
with DBChart1 do
begin
with Series1 do
begin
//series1.Clear;
// series1.Active := false;
adoquery1.Active := True;
DataSource := adoquery1;
XLabelsSource := 'hc';
YValues.ValueSource := 'crcs';
// series1.Active := true;
end;
end;
end
else
begin
statusbar1.Panels[1].Text := '0';
application.MessageBox('没有数据!', '提示', 64);
end;
end;
end;
begin
sqlstring := 'select xm,zjhm,csrq,gjdqdm,count(xm) as crcs from BJ_YW_T_CRJRYDK Where (crrq between ''' + start_date + '''' + ' and ' + '''' + end_date + ''') ' + ' GROUP BY xm, zjhm, csrq, gjdqdm HAVING COUNT(xm) ' + cxtj + cxtextedit1.Text + ' order by crcs desc';
//showmessage(sqlstring);
dbgrid1.Columns[0].Title.caption := '姓 名';
dbgrid1.Columns[0].Width := 300;
dbgrid1.Columns[0].FieldName := 'xm';
dbgrid1.Columns[1].Title.caption := '证件号码';
dbgrid1.Columns[1].Width := 186;
dbgrid1.Columns[1].FieldName := 'zjhm';
dbgrid1.Columns[2].Title.caption := '出生日期';
dbgrid1.Columns[2].Width := 100;
dbgrid1.Columns[2].FieldName := 'csrq';
dbgrid1.Columns[3].Title.caption := '国家代码';
dbgrid1.Columns[3].Width := 100;
dbgrid1.Columns[3].FieldName := 'gjdqdm';
dbgrid1.Columns[4].Title.caption := '出入次数';
dbgrid1.Columns[4].Width := 100;
dbgrid1.Columns[4].FieldName := 'crcs'; with adoquery1 do
begin
Close;
sql.Clear;
sql.Add(sqlstring);
Open;
end;
if adoquery1.RecordCount > 0 then
begin
num := inttostr(adoquery1.RecordCount);
statusbar1.Panels[1].Text := num;
bitbtn3.Enabled := true;
bitbtn6.Enabled := true;
bitbtn1.Enabled := false;
dbgrid1.Columns[0].font.Color := clRed;
dbgrid1.Columns[1].font.Color := clWindowText;
dbgrid1.Columns[2].font.Color := clWindowText;
DBChart1.Title.Text[0] := '出入境人员过境次数统计示意图';
with DBChart1 do
begin
with Series1 do
begin
//Series1.Clear;
//series1.Active := false;
adoquery1.Active := True;
DataSource := adoquery1;
XLabelsSource := 'xm';
YValues.ValueSource := 'crcs';
// series1.Active := true;
end;
end;
end
else
begin
statusbar1.Panels[1].Text := '0';
application.MessageBox('没有数据!', '提示', 64);
end;
end
else if radiobutton2.Checked = true then
begin
sqlstring := 'select hc,jwgjbs,jngjbs,gjdqdm,count(hc) as crcs from BJ_YW_T_CRJJTGJDK Where (crrq between ''' + start_date + '''' + ' and ' + '''' + end_date + ''') ' + ' GROUP BY hc, jwgjbs, jngjbs, gjdqdm HAVING COUNT(hc) ' + cxtj + cxtextedit1.Text + ' order by crcs desc';
dbgrid1.Columns[0].Title.caption := '车辆牌号';
dbgrid1.Columns[0].Width := 200;
dbgrid1.Columns[0].FieldName := 'hc';
dbgrid1.Columns[1].Title.caption := '境外标识';
dbgrid1.Columns[1].Width := 150;
dbgrid1.Columns[1].FieldName := 'jwgjbs';
dbgrid1.Columns[2].Title.caption := '境内标识';
dbgrid1.Columns[2].Width := 150;
dbgrid1.Columns[2].FieldName := 'jngjbs';
dbgrid1.Columns[3].Title.caption := '国家地区';
dbgrid1.Columns[3].Width := 100;
dbgrid1.Columns[3].FieldName := 'gjdqdm';
dbgrid1.Columns[4].Title.caption := '出入次数';
dbgrid1.Columns[4].Width := 100;
dbgrid1.Columns[4].FieldName := 'crcs';
with adoquery1 do
begin
close;
sql.Clear;
sql.Add(sqlstring);
//showmessage(sqlstring);
Open;
end;
if adoquery1.RecordCount > 0 then
begin
num := inttostr(adoquery1.RecordCount);
statusbar1.Panels[1].Text := num;
bitbtn3.Enabled := true;
bitbtn6.Enabled := true;
bitbtn1.Enabled := false;
dbgrid1.Columns[0].font.Color := clRed;
dbgrid1.Columns[1].font.Color := clWindowText;
dbgrid1.Columns[2].font.Color := clWindowText;
DBChart1.Title.Text[0] := '出入境车辆过境次数统计示意图';
with DBChart1 do
begin
with Series1 do
begin
//series1.Clear;
// series1.Active := false;
adoquery1.Active := True;
DataSource := adoquery1;
XLabelsSource := 'hc';
YValues.ValueSource := 'crcs';
// series1.Active := true;
end;
end;
end
else
begin
statusbar1.Panels[1].Text := '0';
application.MessageBox('没有数据!', '提示', 64);
end;
end;
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货