就是构造sql啊 var sqlstr:string; firsttj:boolean; begin sqlstr:='select * from table1'; firsttj:=true;if checkbox1.checked or checkbox2.checked or checkbox3.checked then sqlstr:=sqlstr+' where ';if checkbox1.checked then begin sqlstr:=sqlstr+'...'(学历的条件); firsttj:=false; end;if checkbox2.checked then begin if firsttj then sqlstr:=sqlstr+' and '; sqlstr:=sqlstr+'...'(职务的条件); firsttj:=false; end;if checkbox3.checked then begin if firsttj then sqlstr:=sqlstr+' and '; sqlstr:=sqlstr+'...'(户口的条件); end;end;
小弟初学 请问(学历的条件)这 应该添什么?还有 sqlstr:=sqlstr+' where '; 这需要加什么么???
比如选择所有"学历为本科,并且户口是北京"的人的sql语句这样写: select * from table1 where xl = "本科" and hk = "北京"; "table1"是你数据库表名,"xl"和"hk"是字段名(根据你数据库具体情况修改) xl = "本科" 就是学历的条件,这个你自己设置关键是你要理解sql语句.如果你知道sql该怎么写,那么剩下的就仅仅是用程序来构造一个你要的sql语句而已.
谢谢~您看我改的有问题么? var sqlstr:string; firsttj:boolean; begin sqlstr:='select * from 我的表名'; firsttj:=true;if checkbox1.checked or checkbox2.checked or checkbox3.checked then sqlstr:=sqlstr+' where ';if checkbox1.checked then begin sqlstr:=sqlstr+'xueli like '+'''%'+ComboBox1.Text+'%'''''; firsttj:=false; end;if checkbox2.checked then begin if firsttj then sqlstr:=sqlstr+' and '; sqlstr:=sqlstr+'zhiwu like '+'''%'+ComboBox1.Text+'%'''''; firsttj:=false; end;if checkbox3.checked then begin if firsttj then sqlstr:=sqlstr+' and '; sqlstr:=sqlstr+'bumen like '+'''%'+ComboBox1.Text+'%''''' end;end;
我写的 ComboBox 是 1 2 3 不是都是1!
sqlstr:=sqlstr+'xueli like '+'''%'+ComboBox1.Text+'%'''''; 最后多一个单引号 sqlstr:=sqlstr+'xueli like '+'''%'+ComboBox1.text+'%''';
var
sqlstr:string;
firsttj:boolean;
begin
sqlstr:='select * from table1';
firsttj:=true;if checkbox1.checked or checkbox2.checked or checkbox3.checked then
sqlstr:=sqlstr+' where ';if checkbox1.checked then
begin
sqlstr:=sqlstr+'...'(学历的条件);
firsttj:=false;
end;if checkbox2.checked then
begin
if firsttj then
sqlstr:=sqlstr+' and ';
sqlstr:=sqlstr+'...'(职务的条件);
firsttj:=false;
end;if checkbox3.checked then
begin
if firsttj then
sqlstr:=sqlstr+' and ';
sqlstr:=sqlstr+'...'(户口的条件);
end;end;
sqlstr:=sqlstr+' where '; 这需要加什么么???
select * from table1 where xl = "本科" and hk = "北京";
"table1"是你数据库表名,"xl"和"hk"是字段名(根据你数据库具体情况修改)
xl = "本科" 就是学历的条件,这个你自己设置关键是你要理解sql语句.如果你知道sql该怎么写,那么剩下的就仅仅是用程序来构造一个你要的sql语句而已.
var
sqlstr:string;
firsttj:boolean;
begin
sqlstr:='select * from 我的表名';
firsttj:=true;if checkbox1.checked or checkbox2.checked or checkbox3.checked then
sqlstr:=sqlstr+' where ';if checkbox1.checked then
begin
sqlstr:=sqlstr+'xueli like '+'''%'+ComboBox1.Text+'%''''';
firsttj:=false;
end;if checkbox2.checked then
begin
if firsttj then
sqlstr:=sqlstr+' and ';
sqlstr:=sqlstr+'zhiwu like '+'''%'+ComboBox1.Text+'%''''';
firsttj:=false;
end;if checkbox3.checked then
begin
if firsttj then
sqlstr:=sqlstr+' and ';
sqlstr:=sqlstr+'bumen like '+'''%'+ComboBox1.Text+'%'''''
end;end;
最后多一个单引号
sqlstr:=sqlstr+'xueli like '+'''%'+ComboBox1.text+'%''';