请大家花五分钟帮我解答个问题!我花了两天都没解决!由于正在作毕业设计,很急啊!谢了 ( 积分: 50 )

  • 主题发起人 主题发起人 army430010
  • 开始时间 开始时间
A

army430010

Unregistered / Unconfirmed
GUEST, unregistred user!
我用adoquery时,老是出现问题。
当我用参数进行查询时老是出现parameter‘a’not found(代码如下)
(注:单独做个工程没问题,可把他用在出现用两次用adoquery的窗体中就出现问题)
with adoquery do
begin
close;
sql.clear;
sql.add('select * from biao where xingming=:a');
parameters.parameterbyname('a').value:=edit.text;
open;
end;
当我用sql:='select * from biao where xingming=‘+''''+trim(edit.text)+''''
sql.add('sql');时
出现无效sql语句,期待select delete update出现,这类问题怎么解决!
请求高手们多多指教啊!很急!!!
 
sql:='select * from biao where xingming='+''''+trim(edit.text)+'''';
sql.add('sql');
应该为
sql:='select * from biao where xingming='+''''+trim(edit.text)+'''';
sql.add(sql);

sql:='select * from biao where xingming='''+trim(edit.text)+'''';
sql.add(sql);
 
第二问是笔误,感谢楼上的解答,不好意思啊
无主要的问题是第一问啊,
为什么会找不到参数a呢?
是不是adoquery在一个窗体里用两次就会出现参数混乱啊?
那该怎么办呢?
 
第二问题用二楼的方法还是报出那错误
 
adoquery的connection的属性是在什么地方设置的呢?
 
请问楼主,如果要查询的的姓名条件中出现了"'"(引号),你所拼的sql语句能执行吗?
你第二种方法的前提是用户输入的条件中没有非法字符。
用parameterbyname的方法是最合适的,在用之前先把参数clear,然后再给参数赋值。
 
估计啥都没错,就是ADOQuery没连什么数据源,呵呵
 
俺也不多说了,按的表达能力很有限啊
要是当面,早把问题给你解决了啊。

好了,给你一段代码,看一下,我想你的问题应给会解决的。
我是直接从程序里COPY的,汉字是乱码。


procedure Tfrm_NewTelBusiness.FormCreate(Sender: TObject);
begin

qryTelNewBusiness.Connection:= DM_Main.conn_Main;
qryTelNewBusiness.CommandTimeout:=600;

qryTelNewBusinessSelect.Connection:=DM_Main.conn_Main;
qryTelNewBusinessSelect.CommandTimeout:=600;

qryTelNewBusinessDetailSelect.Connection:=DM_Main.conn_Main;
qryTelNewBusinessDetailSelect.CommandTimeout:=600;

ADOStoredProc1.Connection:=DM_Main.conn_Main;
ADOStoredProc1.CommandTimeout:=600;
end;

procedure Tfrm_NewTelBusiness.SpeedButton2Click(Sender: TObject);
var
ID : string;
a :oleVariant;
i :integer;
begin
if trim(edtAcceptPerson.Text)='' then
begin
Showmessage('??ê?è?êüàíè?D???');
exit;
end;
if trim(edtCustomerName.Text)='' then
begin
showmessage('??ê?è??í?§D???');
exit;
end;

if trim(edtTelNumber.Text)='' then
begin
showmessage('??ê?è?×°?úo???');
exit;
end;
if trim(edtTelAddress.Text)='' then
begin
ShowMessage('??ê?è?°2×°μ??·');
exit;
end;
// if trim(cmbTelType.Text)='' then
// begin
// showmessage('??????°2×°ààDí');
// exit;
// end;


if not DM_MAin.conn_Main.InTransaction then
begin
DM_MAin.conn_Main.BeginTrans;
try
ADOStoredProc1.Close;
ADOStoredProc1.Prepared:=False;
ADOStoredProc1.ProcedureName:='P_GetTelYMD';
ADOStoredProc1.Parameters.Clear;
ADOStoredProc1.Parameters.CreateParameter('@ID',ftString,pdOutput,11,a);
ADOStoredProc1.Prepared:=True;
ADOStoredProc1.ExecProc;
ID:=ADOStoredProc1.Parameters.ParamByName('@ID').Value;

{ D???μ??°òμ??μ?í·±í???? }
qryTelNewBusiness.Close;
qryTelNewBusiness.sql.Clear;
qryTelNewBusiness.SQL.Text:='insert into tbl_TelBusinessHeader(AcceptID,AcceptDate,AcceptPerson,CustomerName,CustomerCard,CustomerAddress,CustomerTel,TelNumber,TelAddress,TelType,TelPrice,TelDeposit,TelFavourable) '+
' values(:AcceptID,:AcceptDate,:AcceptPerson,:CustomerName,:CustomerCard,:CustomerAddress,:CustomerTel,:TelNumber,:TelAddress,:TelType,:TelPrice,:TelDeposit,:TelFavourable)';
qryTelNewBusiness.Parameters.ParamByName('AcceptID').Value:=ID;
qryTelNewBusiness.Parameters.ParamByName('AcceptDate').Value:=strToDate(formatdatetime('yyyy-mm-dd',dt_AcceptDate.DateTime));
qryTelNewBusiness.Parameters.ParamByName('AcceptPerson').Value:=trim(edtAcceptPerson.Text);
qryTelNewBusiness.Parameters.ParamByName('CustomerName').Value:=trim(edtCustomerName.Text);
//éí·Y?¤o???
if trim(edtCustomerCard.Text)='' then
qryTelNewBusiness.Parameters.ParamByName('CustomerCard').Value:=null
else
qryTelNewBusiness.Parameters.ParamByName('CustomerCard').Value:=trim(edtCustomerCard.Text);
//?í?§áa?μμ??·
if trim(edtCustomerAddress.Text)='' then
qryTelNewBusiness.Parameters.ParamByName('CustomerAddress').Value:=null
else
qryTelNewBusiness.Parameters.ParamByName('CustomerAddress').Value:=trim(edtCustomerAddress.Text);
//?í?§áa?μμ??°
if trim(edtCustomerTel.Text)='' then
qryTelNewBusiness.Parameters.ParamByName('CustomerTel').Value:=null
else
qryTelNewBusiness.Parameters.ParamByName('CustomerTel').Value:=trim(edtCustomerTel.Text);

//?í?§×°?úo???
qryTelNewBusiness.Parameters.ParamByName('TelNumber').Value:=trim(edtTelNumber.Text);
//×°?úμ??·
qryTelNewBusiness.Parameters.ParamByName('TelAddress').Value:=trim(edtTelAddress.Text);
// ×°?úààDí
qryTelNewBusiness.Parameters.ParamByName('TelType').Value:=trim(cmbTelType.Text);
//3é??????
if trim(edtTelPrice.Text)='' then
qryTelNewBusiness.Parameters.ParamByName('TelPrice').Value:=null
else
qryTelNewBusiness.Parameters.ParamByName('TelPrice').Value:=strtofloat(trim(edtTelPrice.Text));
//?o?e
if trim(edtTelDeposit.text)='' then
qryTelNewBusiness.Parameters.ParamByName('TelDeposit').Value:=null
else
qryTelNewBusiness.Parameters.ParamByName('TelDeposit').Value:=StrToFloat(trim(edtTelDeposit.text));
//ó??Y????
if trim(edtTelFavourable.Text)='' then
qryTelNewBusiness.Parameters.ParamByName('TelFavourable').Value:=null
else
qryTelNewBusiness.Parameters.ParamByName('TelFavourable').Value:=trim(edtTelFavourable.Text);

qryTelNewBusiness.Prepared:=true;
qryTelNewBusiness.ExecSQL;

{D???μ??°òμ??μ??÷??????}
if ListView_TelGongNeng.Items.Count>0 then
begin
for i:=0 to ListView_TelGongNeng.Items.Count-1 do
begin
qryTelNewBusiness.Close;
qryTelNewBusiness.SQL.Clear;
qryTelNewBusiness.SQL.Text:='insert into tbl_TelBusinessDetail(AcceptID,TelNumber,TelGongNeng) values(:AcceptID,:TelNumber,:TelGongNeng)';
qryTelNewBusiness.Parameters.ParamByName('AcceptID').Value:=ID;
qryTelNewBusiness.Parameters.ParamByName('TelNumber').Value:=trim(edtTelNumber.Text);
qryTelNewBusiness.Parameters.ParamByName('TelGongNeng').Value:=trim(ListView_TelGongNeng.Items.Item.Caption);
qryTelNewBusiness.ExecSQL;
end;
end;
//ìá??ê???
DM_MAin.conn_Main.CommitTrans;
ShowMessage('D???μ??°òμ??3é1|');
except
on e:exception do
begin
DM_MAin.conn_Main.RollbackTrans; //??1?ê???
ShowMessage('D???μ??°òμ??꧰ü£?꧰ü?-òòê?£o'+e.Message);
exit;
end;
end;
end;

{??ê?D???μ?μ??°òμ??D??¢}
//--??ê?í·D??¢
qryTelNewBusinessSelect.Close;
qryTelNewBusinessSelect.SQL.Clear;
qryTelNewBusinessSelect.SQL.Text:='select * from tbl_TelBusinessHeader where AcceptID='''+ID+'''';
qryTelNewBusinessSelect.Open;
//---??ê??÷??D??¢
qryTelNewBusinessDetailSelect.Close;
qryTelNewBusinessDetailSelect.SQL.Clear;
qryTelNewBusinessDetailSelect.SQL.Text:='select * from tbl_TelBusinessDetail where AcceptID=:AcceptID and TelNumber=:TelNumber';
qryTelNewBusinessDetailSelect.DataSource:=DataSourceTelHeader;
qryTelNewBusinessDetailSelect.Open;
 
虽然不是用你们的方法,当还是有收获。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
595
import
I
后退
顶部