菜鸟:SQL查询问题(100分)

  • 主题发起人 主题发起人 wohoot
  • 开始时间 开始时间
W

wohoot

Unregistered / Unconfirmed
GUEST, unregistred user!
数据表:字段A,学生名字,字段B,学生籍贯,字段C,语文成绩,字段D,数学成绩
我窗口有combobox1,显示数据表字段,如:名字.籍贯.语文等,cimbobox2,有=,>,<,like等,EDIT1,用来填写要查询的内容,
希望将combobox1,combobox2.edit1的内容显示在memo1中,如:语文>60等
现在要用query1.SQL.Addstrings(memo2.Lines);来查询,请问我要怎么样写,敬请写出完全代码.
 
var
str, str1, str2: string;
begin
str := ComboBox1.Text;
str1 := ComboBox2.Text;
str2 := Edit1.Text;
memo2.lines.add('select' + str + ' from table where ' + str + str1 + str2);
end;
 
上面的不行啊
 
begin
with Memo1 do
begin
Clear;
Add(CoboBox1.Text);
Add(CoboBox2.Text);
Add(Edit1.Text);
end;
Query1.SQL.Clear;
Query1.SQL.Add(Memo1.Text);
end;
 
怎么还不给分!?
 
var
str, str1, str2: string;
begin
with Memo1 do
begin
Clear;
Add(CoboBox1.Text);
Add(CoboBox2.Text);
Add(Edit1.Text);
end;
Query1.SQL.Clear;
Query1.SQL.Add(Memo1.Text);
end;
 
汗~~~!楼上2位真强
 
请教上面的代码能够用SQL实现吗?
 
不能这么写,对不起,刚才没看清
 
感谢大家的指点,问题是还没有解决啊.
难道就没有一个高手可以写出完全代码吗?
 
不好意思,没调好,一起学习吧!:)
 
var
str:string;
begin
str:='';
if trim(combobox1.text)='学生名字' then str='字段A'
else if trim(combobox1.text)='学生籍贯' then str='字段B'
else if trim(combobox1.text)='语文成绩' then str='字段C'
else if trim(combobox1.text)='数学成绩' then str='字段D'
else exit;
if triM(combobox2.text)<>'' and trim(edit1.text)<>'' then
str:=str+trim(combobox2.text)+quotedstr(edit1.text);
memo1.lines.add(trim(combox1.text)+trim(combobox2.text)+trim(edit1).text);
with query1 do
begin
disablecontrols;
close;
sql.clear;
sql.text:='select * from tablename where 1=1 '+str;
open;
enablecontrols;
end;
你自已调试一下吧,不知道是不是这样子
 
感谢各位的指点,我根据大家的意见写了如下代码,却通不过,提示参数不足,请再指教:
if (triM(combobox1.text)<>'') and (triM(combobox2.text)<>'') and (trim(edit13.text)<>'') then
memo2.lines.Add('select ' +combobox1.Text+' from dukou');
memo2.lines.add('where '+trim(edit14.text)+trim(combobox2.text)+trim(edit13.text));
with query1 do
begin
close;
sql.clear;
sql.Addstrings(memo2.lines);
open;
end;
end;
说明:dukou:数据表名称,combobox1:字段名称;combobox2:逻辑符号;edit13:查询条件;memo2:SQL语句容器
 
看的不是太懂,不过似乎是要达到如下效果:
1.Memo1中显示SQL
2.Sql直接从Memo1中调SQL查询
如果我理解错误不好意思
如果是这样的话,则只要强调一点就是ComboBox2中可能会出现like
所以你
var
blike: Boolean;
temp: string;
一下
begin
if UpperCase(trim(self.ComboBox2.text))='LIKE' then
blike:= true else blike:= false;
temp:='select * from ' + tablename + ' where '+
self.ComboBox1.text+' '+self.ComboBox2.text+' ''+self.edit1.text;
if blike then temp:= temp+'%'' 'else temp:=temp+'' ';
self.Memo1.text:= temp;
end;
如果我没理解错误的话,请注意空格和'的个数
没有调试,应该没问题。。。
 
漏了
if UpperCase(trim(self.ComboBox2.text))='LIKE' then
blike:= true else blike:= false;
temp:='select * from ' + tablename + ' where '+
self.ComboBox1.text+' '+self.ComboBox2.text+' '''+self.edit1.text;
if blike then temp:= temp+'%'' 'else temp:=temp+''' ';
self.Memo1.text:= temp;
 
感谢,正在加油理解,调试
 
感谢你的执教,尽管我还没有解决问题,还是一样送分,同时希望你再指点:我的E-mail:wohoot@163.com;也许市我没有表达清楚,我的意思是:我要用SQL进行查询,
select dbcombobox1.text form 数据库表 where dbcombobox1.text combobox1.text edit3.text
其中:dbcombobox1下拉内容为字段名,随着数据库表的变化而变化
数据库表:随着另外一个事件的发生而变化
combobox1:有<,>,=,like等
edit1:查询的条件,变量
同时为了验证语句的正确,用MEMO1显示SQL语句.
 
后退
顶部