比如我想在程序运行的时候运行这样一个SQL语句:select * from cust where name='张三' and sex='女'
在ADOQuery1.SQL.Add('select * from cust where ');中where后面如何表示'name' 'sex' '='等字段及符号
我试过以下语句行不通:begin
var X:string;
try
with Form1 do
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('select * from cust where'+':X');
X:='FlatComboBox15.text+FlatComboBox16.text+FlatComboBox17.text+''+FlatComboBox18.text
+''+FlatComboBox19.text+FlatComboBox20.text+FlatComboBox21.text;'
//FlatComboBox为下拉框选择的字段,条件和符号.比如姓名、=、张三等等
ADOQuery1.Parameters.ParamByName('X').value:=FlatComboBox16.text;
ADOQuery1.Prepare;
ADOQuery1.OPEN;
end;
except
showmessage('sorry!你的查询有误');
exit;
end;
在ADOQuery1.SQL.Add('select * from cust where ');中where后面如何表示'name' 'sex' '='等字段及符号
我试过以下语句行不通:begin
var X:string;
try
with Form1 do
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('select * from cust where'+':X');
X:='FlatComboBox15.text+FlatComboBox16.text+FlatComboBox17.text+''+FlatComboBox18.text
+''+FlatComboBox19.text+FlatComboBox20.text+FlatComboBox21.text;'
//FlatComboBox为下拉框选择的字段,条件和符号.比如姓名、=、张三等等
ADOQuery1.Parameters.ParamByName('X').value:=FlatComboBox16.text;
ADOQuery1.Prepare;
ADOQuery1.OPEN;
end;
except
showmessage('sorry!你的查询有误');
exit;
end;
解决方案 »
- a,b为两个相同的动态数组,a=b是指针赋值还是拷贝内容?
- EDBEngine Error是怎么回事啊?
- 请问如何得到数据库的当前记录?
- !!!产生非典抗体的方法!!!
- 怎样删除String中的某个字符?(如把"$6655726"中的"$"去掉,或把"255 255 0"中第二个空格去掉)??
- DELPHI调用WORD 2000是不是有问题----特别不稳定(是DELPHI的BUG?)
- TCP如何知道已接收完数据
- 再问用DELPHI联EXCEL的问题!
- TDllProcedure是个什么类型老使说undeclared indentifier
- 谁知道冰河的搜索功能是如何实现的?
- 程序退出时,退出提示问题?
- Delphi 读写文件
begin
var X:string;
try
with Form1 do
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
X := FlatComboBox15.text+FlatComboBox16.text+FlatComboBox17.text+' '+
FlatComboBox18.text+' '+FlatComboBox19.text+FlatComboBox20.text+FlatComboBox21.text;
ADOQuery1.SQL.Add('select * from cust where ' + X);
ADOQuery1.OPEN;
end;
except
showmessage('sorry!你的查询有误');
exit;
end;
Parameters.ParamByName('name').value:=FlatComboBoxname.text;
Parameters.ParamByName('sex').value:=FlatComboBoxsex.text;
select * from cust where sex='女' and name='张三'
select * from cust where name='张三' and sex='女' and age='19'
select * from cust where name='张三'
等等多种组合,
select * from name='张三',如何把库里面的name字段跟ComboBox选出的‘姓名’对应起来
select * from a,b where a.id=b.id 类似这样的
var sqlstr:stringsqlstr:='select * from cust'
if FlatComboBox1.text<>'' then
sqlstr:=sqlstr+'where name='+'''+FlatComboBox1.text+'''
if FlatComboBox2.text<>'' then
sqlstr:=sqlstr+'and'+'''+FlatComboBox2.text+'''adoquery1.sql.add('sqlstr')这样做的话如果条件比较多就麻烦
哎~~ 都没有一个满意的答案
form开始的时候定义,或者是开始重新设定条件前:sqlstr='select * from cust where 1=1' (新增条件)BUTTON的单击事件里面加:
//fieldComboBox.text 字段名
//processComboBox.text 运算符
//valueTextBox 值
begin
if (fieldComboBox.text <>'') and (processComboBox.text <>'') then
sqlstr:=sqlstr+'and '''+fieldComboBox.text+''' '+processComboBox.text +' '''+valueTextBox.text+'''';
adoquery1.sql.clear;
adoquery1.sql.add(sqlstr)
end;可能单引号有不对,自己再调调!