真是新手! if combobox1.Text='索引书号' then begin SQL.Text:='select * from book where 索引书号.value='+form1.edit1.text; …… …… end;
sql.text:='select * from book where 字段名='''+form1.edit1.text+'''
sql.clear; sql.add('select * from book where 字段名=:p'); paramByName('p').AsString = form1.edit1.text; 這樣寫清晰
我比较喜欢这种写法,在参数比较多的情况下看起来很清晰:with Query1 do begin Close; SQL.Clear; SQL.Add(Format('select * from book where XXXX=''%s''', [Edit1.Text])); end;
ntext类型不能用’=‘,要用‘LIKE’你可以查以查SQL的帮助。
with datamodule2.Query1 do begin if active=true then close; unprepare; if combobox1.Text='索引书号' then begin sql.clear; SQL.add('select * from book where 索引书号.value=:xxx'); parambyname('xxx').asstring:=form1.edit1.text'; prepare; open; end; end;
if combobox1.Text='索引书号' then
begin
SQL.Text:='select * from book where 索引书号.value='+form1.edit1.text;
……
……
end;
sql.add('select * from book where 字段名=:p');
paramByName('p').AsString = form1.edit1.text;
這樣寫清晰
begin
Close;
SQL.Clear;
SQL.Add(Format('select * from book where XXXX=''%s''', [Edit1.Text]));
end;
begin
if active=true then
close;
unprepare; if combobox1.Text='索引书号' then
begin
sql.clear;
SQL.add('select * from book where 索引书号.value=:xxx');
parambyname('xxx').asstring:=form1.edit1.text';
prepare;
open;
end;
end;