delphi运行时提示from 子语句错误,各位大侠给看看
procedureTForm1.Button1Click(Sender:TObject);varcx,cx1,cx2,cx3,cx4,cx5,cx6,cx7:string...
procedure TForm1.Button1Click(Sender: TObject);
var cx, cx1,cx2,cx3,cx4,cx5,cx6,cx7:string;
begin
if c1.Checked then //按学号查询
cx1:='xh like'+'"'+'%'+ dbedit1.Text +'%'+'"';
if c2.Checked then //安班号查询
cx2:='bh like'+'"'+'%'+dbedit2.Text +'%'+'"';
if c3.Checked then //按姓名查询
cx3:='xm like'+'"'+'%'+dbedit3.Text +'%'+'"';
if c4.Checked then //按性别查询
begin
if rp1.ItemIndex=0 then
cx4:='xb like'+'"'+'男%'+'"';
if rp1.ItemIndex =1 then
cx4:='xb like'+'"'+'女%'+'"';
end;
if c5.Checked then //按出生日期查询
cx5:='sr># '+datetostr(datetimepicker2.Date ) +'#and sr<#'+datetostr(datetimepicker1.date) ;
if c6.Checked then //按政治面貌查询
cx6:='zz like'+'"'+'%'+dbcombobox1.Text +'%' +'"' ;
if c7.Checked then //按总分查询
cx7:='zf >='+ dbedit4.Text +'and zf<='+dbedit5.Text ;
cx:='select * from xs where'+cx1+'and'+cx2+'and'+cx3+'and'+cx4+'and'+cx5+'and'+cx6+'and'+cx7 ;
adoquery1.Close ;
adoquery1.sql.Clear;
adoquery1.SQL.Add(cx);
adoquery1.Open ;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;
大侠给看看存在什么问题,运行总是不能成功, 按照 回答者:bluedn 说的改了后又提示“语法错误(操作符丢失)在查询表达式‘xh like“%002%” and and and and and and'中
是and后缺少表达式吗?
程序运行时如果某一个复选框没有被选中,where后面就会出现and空 所以需要在初始时赋予cx1-cx7 一个值,才能避免出现and and and。。这种情况, 那么应该在初始时给cx1-cx7个什么值呢? 展开
var cx, cx1,cx2,cx3,cx4,cx5,cx6,cx7:string;
begin
if c1.Checked then //按学号查询
cx1:='xh like'+'"'+'%'+ dbedit1.Text +'%'+'"';
if c2.Checked then //安班号查询
cx2:='bh like'+'"'+'%'+dbedit2.Text +'%'+'"';
if c3.Checked then //按姓名查询
cx3:='xm like'+'"'+'%'+dbedit3.Text +'%'+'"';
if c4.Checked then //按性别查询
begin
if rp1.ItemIndex=0 then
cx4:='xb like'+'"'+'男%'+'"';
if rp1.ItemIndex =1 then
cx4:='xb like'+'"'+'女%'+'"';
end;
if c5.Checked then //按出生日期查询
cx5:='sr># '+datetostr(datetimepicker2.Date ) +'#and sr<#'+datetostr(datetimepicker1.date) ;
if c6.Checked then //按政治面貌查询
cx6:='zz like'+'"'+'%'+dbcombobox1.Text +'%' +'"' ;
if c7.Checked then //按总分查询
cx7:='zf >='+ dbedit4.Text +'and zf<='+dbedit5.Text ;
cx:='select * from xs where'+cx1+'and'+cx2+'and'+cx3+'and'+cx4+'and'+cx5+'and'+cx6+'and'+cx7 ;
adoquery1.Close ;
adoquery1.sql.Clear;
adoquery1.SQL.Add(cx);
adoquery1.Open ;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;
大侠给看看存在什么问题,运行总是不能成功, 按照 回答者:bluedn 说的改了后又提示“语法错误(操作符丢失)在查询表达式‘xh like“%002%” and and and and and and'中
是and后缺少表达式吗?
程序运行时如果某一个复选框没有被选中,where后面就会出现and空 所以需要在初始时赋予cx1-cx7 一个值,才能避免出现and and and。。这种情况, 那么应该在初始时给cx1-cx7个什么值呢? 展开
3个回答
展开全部
没有必要给每个查询条件设一个变量
procedure TForm1.Button1Click(Sender: TObject);
var whereStr:string;
begin
if c1.Checked and dbedit1.Text <>'' then //按学号查询
whereStr:='xh like'+'"'+'%'+ dbedit1.Text +'%'+'"';
if c2.Checked and dbedit2.Text<>'' then //安班号查询
if whereStr<>'' then
whereStr:=whereStr+' and bh like'+'"'+'%'+dbedit2.Text +'%'+'"'
else
whereStr:='bh like'+'"'+'%'+dbedit2.Text +'%'+'"';
if c3.Checked and dbedit3.Text <>'' then //按姓名查询
if whereStr<>'' then
whereStr:=whereStr+' and xm like'+'"'+'%'+dbedit3.Text +'%'+'"'
else
whereStr:='xm like'+'"'+'%'+dbedit3.Text +'%'+'"';
if c4.Checked then //按性别查询 这里不是男就是女用1个IF...ELSE...语句就行了而且也没必要用like直接=就行了
begin
if whereStr<>'' then
if rp1.ItemIndex=0 then
whereStr:=whereStr+' and xb =+'"'+'男'+'"'
else
whereStr:=whereStr+' and xb =+'"'+'女'+'"'
else
if rp1.ItemIndex=0 then
whereStr:='xb =+'"'+'男'+'"'
else
whereStr:='xb =+'"'+'女'+'"';
end;
if c5.Checked then //按出生日期查询
if whereStr<>'' then
whereStr:=' and sr># '+datetostr(datetimepicker2.Date ) +'#and sr<#'+datetostr(datetimepicker1.date)
else
whereStr:=' sr># '+datetostr(datetimepicker2.Date ) +'#and sr<#'+datetostr(datetimepicker1.date)
if c6.Checked and dbcombobox1.Text<>'' then //按政治面貌查询
if whereStr<>'' then
whereStr:=whereStr+' and zz like'+'"'+'%'+dbcombobox1.Text +'%' +'"'
else
whereStr:=' zz like'+'"'+'%'+dbcombobox1.Text +'%' +'"' ;
if c7.Checked and dbedit5.Text<>'' then //按总分查询
if whereStr<>'' then
whereStr:=whereStr+' zf >='+ dbedit4.Text +'and zf<='+dbedit5.Text
else
whereStr:=' zf >='+ dbedit4.Text +'and zf<='+dbedit5.Text ;
cx:='select * from xs where '+whereStr;
adoquery1.Close ;
adoquery1.sql.Clear;
adoquery1.SQL.Add(cx);
adoquery1.Open ;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;
procedure TForm1.Button1Click(Sender: TObject);
var whereStr:string;
begin
if c1.Checked and dbedit1.Text <>'' then //按学号查询
whereStr:='xh like'+'"'+'%'+ dbedit1.Text +'%'+'"';
if c2.Checked and dbedit2.Text<>'' then //安班号查询
if whereStr<>'' then
whereStr:=whereStr+' and bh like'+'"'+'%'+dbedit2.Text +'%'+'"'
else
whereStr:='bh like'+'"'+'%'+dbedit2.Text +'%'+'"';
if c3.Checked and dbedit3.Text <>'' then //按姓名查询
if whereStr<>'' then
whereStr:=whereStr+' and xm like'+'"'+'%'+dbedit3.Text +'%'+'"'
else
whereStr:='xm like'+'"'+'%'+dbedit3.Text +'%'+'"';
if c4.Checked then //按性别查询 这里不是男就是女用1个IF...ELSE...语句就行了而且也没必要用like直接=就行了
begin
if whereStr<>'' then
if rp1.ItemIndex=0 then
whereStr:=whereStr+' and xb =+'"'+'男'+'"'
else
whereStr:=whereStr+' and xb =+'"'+'女'+'"'
else
if rp1.ItemIndex=0 then
whereStr:='xb =+'"'+'男'+'"'
else
whereStr:='xb =+'"'+'女'+'"';
end;
if c5.Checked then //按出生日期查询
if whereStr<>'' then
whereStr:=' and sr># '+datetostr(datetimepicker2.Date ) +'#and sr<#'+datetostr(datetimepicker1.date)
else
whereStr:=' sr># '+datetostr(datetimepicker2.Date ) +'#and sr<#'+datetostr(datetimepicker1.date)
if c6.Checked and dbcombobox1.Text<>'' then //按政治面貌查询
if whereStr<>'' then
whereStr:=whereStr+' and zz like'+'"'+'%'+dbcombobox1.Text +'%' +'"'
else
whereStr:=' zz like'+'"'+'%'+dbcombobox1.Text +'%' +'"' ;
if c7.Checked and dbedit5.Text<>'' then //按总分查询
if whereStr<>'' then
whereStr:=whereStr+' zf >='+ dbedit4.Text +'and zf<='+dbedit5.Text
else
whereStr:=' zf >='+ dbedit4.Text +'and zf<='+dbedit5.Text ;
cx:='select * from xs where '+whereStr;
adoquery1.Close ;
adoquery1.sql.Clear;
adoquery1.SQL.Add(cx);
adoquery1.Open ;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询