在执行的时候老是说在and或者=附近有问题,是不是哪儿写错了阿var
condition : string;
sql : string;begin
//执行学生信息查询
if (checkbox1.Checked = false) and (checkbox2.Checked = false) and (checkbox3.Checked = false)
and (checkbox4.Checked = false) and (checkbox5.Checked = false) and (checkbox6.Checked = false)
and (checkbox7.Checked = false) and (checkbox8.Checked = false)then
begin
MessageBox(self.Handle, '请选择要打印的内容!', '提示', mb_IconInformation + mb_Ok); end;
condition:=' ';
if CheckBox1.Checked=true then
begin
if condition<>' ' then
begin
condition:=condition+' and ';
end;
condition:=condition+'studentID='+edit1.Text;
end;
if CheckBox2.Checked=true then
begin
if condition<>' ' then
begin
condition:=condition+' and ';
end;
condition:=condition+'name='+edit3.Text;
end;
if CheckBox3.Checked=true then
begin
if condition<>' ' then
begin
condition:=condition+' and ';
end;
condition:=condition+'classID='+combobox1.Text;
end;
if CheckBox4.Checked=true then
begin
if condition<>' ' then
begin
condition:=condition+' and ';
end;
condition:=condition+'grade='+combobox2.Text;
end;
if CheckBox4.Checked=true then
begin
if condition<>' ' then
begin
condition:=condition+' and ';
end;
condition:=condition+'instituteID='+combobox3.Text;
end;
if CheckBox5.Checked=true then
begin
if condition<>' ' then
begin
condition:=condition+' and ';
end;
condition:=condition+'departmentID='+combobox4.Text;
end;
if CheckBox6.Checked=true then
begin
if condition<>' ' then
begin
condition:=condition+' and ';
end;
condition:=condition+'major='+combobox5.Text;
end;
if CheckBox6.Checked=true then
begin
if condition<>' ' then
begin
condition:=condition+' and ';
end;
condition:=condition+'campus='+combobox6.Text;
end;
sql:='select * from students where '+condition;
edit1.Text:=sql;
ADODataSet1.Close;
ADODataSet1.CommandText:=sql;
ADODataSet1.Open;
condition : string;
sql : string;begin
//执行学生信息查询
if (checkbox1.Checked = false) and (checkbox2.Checked = false) and (checkbox3.Checked = false)
and (checkbox4.Checked = false) and (checkbox5.Checked = false) and (checkbox6.Checked = false)
and (checkbox7.Checked = false) and (checkbox8.Checked = false)then
begin
MessageBox(self.Handle, '请选择要打印的内容!', '提示', mb_IconInformation + mb_Ok); end;
condition:=' ';
if CheckBox1.Checked=true then
begin
if condition<>' ' then
begin
condition:=condition+' and ';
end;
condition:=condition+'studentID='+edit1.Text;
end;
if CheckBox2.Checked=true then
begin
if condition<>' ' then
begin
condition:=condition+' and ';
end;
condition:=condition+'name='+edit3.Text;
end;
if CheckBox3.Checked=true then
begin
if condition<>' ' then
begin
condition:=condition+' and ';
end;
condition:=condition+'classID='+combobox1.Text;
end;
if CheckBox4.Checked=true then
begin
if condition<>' ' then
begin
condition:=condition+' and ';
end;
condition:=condition+'grade='+combobox2.Text;
end;
if CheckBox4.Checked=true then
begin
if condition<>' ' then
begin
condition:=condition+' and ';
end;
condition:=condition+'instituteID='+combobox3.Text;
end;
if CheckBox5.Checked=true then
begin
if condition<>' ' then
begin
condition:=condition+' and ';
end;
condition:=condition+'departmentID='+combobox4.Text;
end;
if CheckBox6.Checked=true then
begin
if condition<>' ' then
begin
condition:=condition+' and ';
end;
condition:=condition+'major='+combobox5.Text;
end;
if CheckBox6.Checked=true then
begin
if condition<>' ' then
begin
condition:=condition+' and ';
end;
condition:=condition+'campus='+combobox6.Text;
end;
sql:='select * from students where '+condition;
edit1.Text:=sql;
ADODataSet1.Close;
ADODataSet1.CommandText:=sql;
ADODataSet1.Open;
and (checkbox4.Checked = false) and (checkbox5.Checked = false) and (checkbox6.Checked = false)
and (checkbox7.Checked = false) and (checkbox8.Checked = false)then
最后是不是)和then间少了个空格
select * from tablename where and conditions
:) 删掉那个and 就行了
只需要把
sql:='select * from students where '+condition;
改成
sql:='select * from students where 1=1 and ' + condition;
能大量减少代码行数
这个你不能写成
if CheckBox1.Checked then
吗?
看着so别扭
“= false”你也会写???
什么叫逻辑变量啊?
老师救命。
//sql:='select * from students where 1=1 and ' + condition;//
//能大量减少代码行数长知识