急,请问各位大侠下面这段代码到底有什么错误???(50分)

  • 主题发起人 monster112115
  • 开始时间
M

monster112115

Unregistered / Unconfirmed
GUEST, unregistred user!
急,请问各位大侠下面这段代码到底有什么错误???
我编译时,老是出现list index out of bounds(0)这样的出错提示


procedure TForm3.FlatButton22Click(Sender: TObject);
var
ssql,qssj,jzsj:string;
begin
qssj:=datetostr(datetimepicker1.Date);
jzsj:=datetostr(datetimepicker2.Date);

if (not checkbox1.checked) and (not checkbox2.checked) and (not checkbox3.checked) and
(not checkbox4.checked) and (not checkbox5.checked) and (not checkbox6.checked) and
(not checkbox7.checked) and (not checkbox8.checked) then
MessageDlg('对不起,如果需查询,请先选择查询条件!',mtinformation,[mbok],0)
else
begin
if checkbox1.Checked then
begin
ssql:='where 案件类别=:ajnbp';
end;

if checkbox4.Checked then
begin
ssql:=ssql+''+'and'+''+'作案手段=:zasdp';
end;

if checkbox5.Checked then
begin
ssql:=ssql+''+'and'+''+'作案工具=:zagjp';
end;

if checkbox6.Checked then
begin
ssql:=ssql+''+'and'+''+'主犯姓名=:zfxmp';
end;

if checkbox7.Checked and checkbox8.Checked then
ssql:=ssql+''+'and'+''+'发案时间 <=:jzsjp'+''+'and'+''+'发案时间 >=:qssjp'
else
begin
if checkbox7.Checked then
ssql:=ssql+''+'and'+''+'发案时间 >=:qssjp';
if checkbox8.checked then
ssql:=ssql+''+'and'+''+'发案时间 <=:jzsjp';
end;
end;

adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.sql.Add('select 编号,案件名称');
adoquery2.sql.Add('from 案件');
adoquery2.sql.add(ssql);
adoquery2.Parameters[0].Value:=dbcombobox1.items[dbcombobox1.itemindex];
adoquery2.Parameters[3].Value:=dbcombobox2.Items[dbcombobox2.ItemIndex];
adoquery2.Parameters[4].Value:=dbcombobox3.Items[dbcombobox3.ItemIndex];
adoquery2.Parameters[5].Value:=edit1.text;
adoquery2.Parameters[6].Value:=qssj;
adoquery2.Parameters[7].Value:=jzsj;
adoquery2.prepared ;
adoquery2.Open;
if AdoQuery2.RecordCount=0 then
MessageDlg('对不起,没有您所要查找的资料,请重新选择查询条件!',
mtinformation,[mbok],0);
end;
 
.Parameters[] 1和2 呢,跟踪一下
 
是运行时候的错误吧,不是编译时候的错误吧
问题好大,你的那些参数又不是一定有的,如果没有check对应的box,有些参数是没有的
你怎么能直接不管3721就按01234567来选择参数呢
 
agree pipi
 
to pipi
参数我都定义了
 
比如说,checkbox1 选了,那么param 0 就是 :ajnbp
要是checkbox1没选,checkbox4选了,那么param 0 就是 :zasdp
要是checkbox4也没选……
 
用ParamByName试试,这样比较不容易出错。
 
//SQL参数类型或个数不符
建议:
>adoquery2.prepared ;
//在此加
ShowMessage(adoquey2.SQL);
//在MessageBox出来的时候,按Ctrl+c复制到其他SQL语句分析工具检查一下错误
>adoquery2.Open;
 
还是不行,请问各位大侠动态参数到底如何定义和赋值呀,能给我一个象这样的小例子吗,最好是ado的
 
怎么没有人能回答这个问题吗???
 
找找这几段代码的问题吧
dbcombobox1.items[dbcombobox1.itemindex];
adoquery2.Parameters[3].Value:=dbcombobox2.Items[dbcombobox2.ItemIndex];
adoquery2.Parameters[4].Value:=dbcombobox3.Items[dbcombobox3.ItemIndex];
 
应该是日期错误吧!
 
dbcombobox1.items[dbcombobox1.itemindex];
的初始化有问题。itemindex不能超出现有的范围。
 
谢谢大家!
 
顶部