一个关于数据查询的问题请高手指教

渤海红鱼 2004-11-16 08:57:42
我想做一个这样的程序,
我用的数据库为INterBase我想做一个动态的查询功能,如给用户多个选择项让他来自己进行查询对所选择的内容进行复合查询请个位给于意见,如果有相关的源代码请告诉一下或者是网站。
谢谢
...全文
88 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
渤海红鱼 2004-11-16
  • 打赏
  • 举报
回复
问题是如果程序中包括 and or like 的话程序应该如何来写。请给予指正
jabcf 2004-11-16
  • 打赏
  • 举报
回复
var
sarray:array[1..4]of string;
sboolean:boolean;
sstr:string;
i:integer;
begin
if c1.Checked=true then
sarray[1]:='日期>='+''''+formatdatetime('yyyy-mm-dd',d1.date)+''''+' and 日期<='+''''+formatdatetime('yyyy-mm-dd',d2.date)+''''
else sarray[1]:='';
if c2.Checked=true then sarray[2]:='车型='+''''+sncombobox1.Text+''''
else sarray[2]:='';
if c3.Checked=true then sarray[3]:='颜色='+''''+sncombobox2.Text+''''
else sarray[3]:='';
if c4.Checked=true then sarray[4]:='类别=''出口车'''
else sarray[4]:='';


sboolean:=true;
sstr:='';

for i:=1 to 4 do
begin
if sarray[i]<>'' then
begin
if sboolean=true then
begin
sstr:=sstr+sarray[i];
sboolean:=false;
end
else sstr:=sstr+' and '+sarray[i];
end;
end;
if sstr='' then exit
else sstr:=' where '+sstr;

adoquery1.Close;
adoquery1.SQL.Clear;
sstr:='select * from tablename'+sstr;
adoquery1.SQL.Add(sstr);
adoquery1.open;
其中c1,c2,c3,c4是checkbox
l_spark 2004-11-16
  • 打赏
  • 举报
回复
var
str:string;
begin
if edit1.Text<>'' then
str:='where 性别='+edit1.Text+''
else
str:='';
if edit2.Text<>'' then
begin
if edit1.Text='' then
str:= 'where kkk='+edit2.Text+''
else
str:=str+'and kkk='+edit2.Text+'' ;
end else
str:=str;
if edit3.Text<>'' then
begin
if (edit1.Text='') and (edit2.Text='') then
str:= 'where www='+edit3.Text+''
else
str:=str+'and www='+edit3.Text+'' ;
end else
str:=str ;
SQL语句、、、
coeltdit 2004-11-16
  • 打赏
  • 举报
回复
呵呵,UP。。。。。。。。。。。。
hr168 2004-11-16
  • 打赏
  • 举报
回复
把相应的表的字段列出来,写出相应的含义,这样在用户选择完之后,根据选择的字段添入SQL语句,这个之前就可以判断然后连接出复合语句就可以得到SQL语句,执行~
jinjazz 2004-11-16
  • 打赏
  • 举报
回复
sqlstr:='select * from xx where 1=1'

if edit1.text<>'' then
sqlstr:=sqlstr+' and ...';
if checkbox1.checked then
sqlstr:=sqlstr+' and....';
if combobox1.itemindex>0 then
sqlstr:=sqlstr+' and....';

...就这样就可以了
渤海红鱼 2004-11-16
  • 打赏
  • 举报
回复
思路相同,如果方便请给予可以学习的源代码,谢谢
肥仔胧 2004-11-16
  • 打赏
  • 举报
回复
方法太多种了,控件也太多了
纯粹是SQL语句的应用
BigAngell 2004-11-16
  • 打赏
  • 举报
回复
UP 学习
ztenv 2004-11-16
  • 打赏
  • 举报
回复
你可以先把数据库的各字段译成汉语(建立一一对应关系,汉字提供给用户,用户是不懂你数据库的字段意思的);然后用一两个listbox,一个显示数据库的所有的字段,然后放一个按钮,让用户去选择要查询的字段,把要查询的字段添加到另一个listbox中,然后根据上边建立的一一对应的关系,再泽成数据库的对应的字段,然后查询,显示出来,就可以了;

2,497

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧