这是个查询的问题!能运行,但一点查询的话,就提示format问题,求教各位前辈!procedure Tform_kc.FormCreate(Sender: TObject);
begin
combobox1.Text :='';
combobox2.Text:='';
combobox3.Text :='';
//send man_inf to item
datamodule2.ADOQuery2.Close;
datamodule2.ADOQuery2.SQL.Clear;
datamodule2.ADOQuery2.SQL.Add('select man_nam from man_ifo');
datamodule2.ADOQuery2.open;
datamodule2.ADOQuery2.First;
while not datamodule2.ADOQuery2.Eof do
begin
ComboBox3.Items.Add(datamodule2.ADOQuery2.FieldbyName('man_nam').AsString);
datamodule2.ADOQuery2.Next;
end;
//send pro_inf to item
datamodule2.adoquery2.Close;
datamodule2.adoquery2.SQL.clear;
datamodule2.adoquery2.SQL.add('select pro_nam from pro_ifo');
datamodule2.adoquery2.Open;
datamodule2.adoquery2.first; while not datamodule2.adoquery2.eof do
begin
combobox2.items.add(datamodule2.ADOQuery2.fieldbyname('pro_nam').asstring);
datamodule2.adoquery2.Next;
end;
end;procedure Tform_kc.Button1Click(Sender: TObject);
var
fstr:string;
begin
case combobox1.itemindex of
//pro_id as "物品编号",pro_nam as "物品名称",out_num as "物品数
//量",man_id as "人员编号",man_nam as ""
0: fstr:='select * from out_ifo where(pro_name=%s,man_nam=%s)between(%s) and(%s)';
1: fstr:='select * from in_ifo where(pro_nam=%s,man_nam=%s)between(%s) and(%s)';
2: fstr:='select * from change_ifo where(pro_name=%s,man_nam=%s)between(%s) and(%s)';
3: fstr:='select * from set_ifo where(pro_name=%s,man_nam=%s)between(%s) and(%s)';
4: fstr:='select * from cuz_ifo where(pro_name=%s,man_nam=%s)between(%s) and(%s)';
5: fstr:='select * from flower_ifo where(pro_name=%s,man_mam=%s) between(%s) and (%s)';
end;
{if combobox2.Text:='' or edit3.Text:='' or combobox1.Text:='' then
messagebox(handle,'不能有空白','消息',mb_ok);
exit;
else }
datamodule2.ADOQuery2.close;
datamodule2.ADOQuery2.sql.Clear;
datamodule2.ADOQuery2.SQL.Add(format(fstr,[combobox2.text,combobox3.text,datetimepicker1.date,datetimepicker2.date])); datamodule2.ADOQuery2.Open;end;
begin
combobox1.Text :='';
combobox2.Text:='';
combobox3.Text :='';
//send man_inf to item
datamodule2.ADOQuery2.Close;
datamodule2.ADOQuery2.SQL.Clear;
datamodule2.ADOQuery2.SQL.Add('select man_nam from man_ifo');
datamodule2.ADOQuery2.open;
datamodule2.ADOQuery2.First;
while not datamodule2.ADOQuery2.Eof do
begin
ComboBox3.Items.Add(datamodule2.ADOQuery2.FieldbyName('man_nam').AsString);
datamodule2.ADOQuery2.Next;
end;
//send pro_inf to item
datamodule2.adoquery2.Close;
datamodule2.adoquery2.SQL.clear;
datamodule2.adoquery2.SQL.add('select pro_nam from pro_ifo');
datamodule2.adoquery2.Open;
datamodule2.adoquery2.first; while not datamodule2.adoquery2.eof do
begin
combobox2.items.add(datamodule2.ADOQuery2.fieldbyname('pro_nam').asstring);
datamodule2.adoquery2.Next;
end;
end;procedure Tform_kc.Button1Click(Sender: TObject);
var
fstr:string;
begin
case combobox1.itemindex of
//pro_id as "物品编号",pro_nam as "物品名称",out_num as "物品数
//量",man_id as "人员编号",man_nam as ""
0: fstr:='select * from out_ifo where(pro_name=%s,man_nam=%s)between(%s) and(%s)';
1: fstr:='select * from in_ifo where(pro_nam=%s,man_nam=%s)between(%s) and(%s)';
2: fstr:='select * from change_ifo where(pro_name=%s,man_nam=%s)between(%s) and(%s)';
3: fstr:='select * from set_ifo where(pro_name=%s,man_nam=%s)between(%s) and(%s)';
4: fstr:='select * from cuz_ifo where(pro_name=%s,man_nam=%s)between(%s) and(%s)';
5: fstr:='select * from flower_ifo where(pro_name=%s,man_mam=%s) between(%s) and (%s)';
end;
{if combobox2.Text:='' or edit3.Text:='' or combobox1.Text:='' then
messagebox(handle,'不能有空白','消息',mb_ok);
exit;
else }
datamodule2.ADOQuery2.close;
datamodule2.ADOQuery2.sql.Clear;
datamodule2.ADOQuery2.SQL.Add(format(fstr,[combobox2.text,combobox3.text,datetimepicker1.date,datetimepicker2.date])); datamodule2.ADOQuery2.Open;end;
当然不对了
datamodule2.ADOQuery2.SQL.Add(format(fstr,[combobox2.text,combobox3.text,datetostr(datetimepicker1.date),datetostr(datetimepicker2.date)]));
就没有格式的问题了,可以看一下format的帮助
是不是我这样引用不行呢?
fstr:='select * from in_ifo where(pro_nam=%s,man_nam=%s)between(%s) and(%s)';
//where条件引用和between and,不能这样用%s!各位前辈教教小弟如何
//正确用好嘛?
datamodule2.ADOQuery2.SQL.Add(format(fstr,[combobox2.text,combobox3.text,datetostr(datetimepicker1.date),datetostr(datetimepicker2.date)]));
(pro_nam=%s,man_nam=%s)between(%s) and(%s)???sql好象没有这样的语法吧?
我不知道你的%s是什么,看看下面的行不行
fstr := 'select * from in_ifo where (pro_name= :s1 or man_nam=:s2) and date(???) between :s3 and :s4
adoquery.parameters.parambyname.value := combobox1.text;
.
.
.
between前面缺少表示时间的字段!
现在是这样的
fstr:='select * from in_ifo where(pro_nam=%s and man_nam=%s,in_dat between(%s) and(%s))';
//format语句
datamodule2.ADOQuery2.SQL.Add(format(fstr,[combobox2.text,combobox3.text,datetostr(datetimepicker1.date),datetostr(datetimepicker2.date)]));
运行后数据库中combobox2,text提取并选择一个字段“内存”同理combobox3。text“张三”,选择好时间!点查询的时候出现
“parameter 内存 has no default value",是个class eoleexception错误
究竟是怎么回事情呢?请前辈们指教啊
因为%s参数代替字符串,所以引用时要加单引号:
fstr:='select * from in_ifo where(pro_nam=''%s'',man_nam=''%s'')between(''%s'') and(''%s'')';