procedure TOManage.Button4Click(Sender: TObject);
var
i,k,m: integer;
ordno,tabno,tabname,disno,disname,disprice,sql:string;
begin
k:=0;
while i<listbox3.Items.Count do
if listbox3.Selected[i] then
begin
for m:=0 to listbox2.Items.Count-1 do
with adoquery1 do
begin
k:=k+1;
ordno:=inttostr(k);
tabname:=listbox3.Items[i];
disname:=listbox2.Items[m];
adoquery1.Close;
adoquery1.Sql.Clear;
adoquery1.Sql.Add('select dis_No from dish where dis_Name=disname');//出錯
disno:=FieldByName('dis_No').Value;
adoquery1.Open;
adoquery1.Close;
adoquery1.Sql.Clear;
adoquery1.Sql.Add('select dis_Price from dish where dis_Name =disname');
disprice:=FieldByName('dis_Price').Value;
adoquery1.Open;
adoquery1.close;
adoquery1.SQL.Clear;
adoquery1.Sql.Add('select tab_no from dish where tab_name like tabname');
tabno:=FieldByName('tab_no').Value;
SQl.Text:='insert into orders(ord_no,tab_no,tab_name,dis_No,dis_Name,dis_Price) values('+ordno+','+tabno+','+tabname+','+disno+','+disname+','+disprice+')';
adoquery1.execsql;
end
end
else
i:=i+1;
end;
uj5u.com熱心網友回復:
adoquery1.Sql.Add('select dis_No from dish where dis_Name='+quotedstr(disname));uj5u.com熱心網友回復:
select dis_No from dish where dis_Name=‘‘disname’’uj5u.com熱心網友回復:
//---------------------------------------adoquery1.Close;
adoquery1.Sql.Clear;
adoquery1.Sql.Add('select dis_No from dish where dis_Name=disname');//出錯
disno:=FieldByName('dis_No').Value;
adoquery1.Open;
//-------------------------------------------------------------------------
以上是你的代碼
第三行用1#的替換下
倒數第一行和倒數第二行交換一下。
uj5u.com熱心網友回復:
引數disname不能直接在字串引號‘’中間直接用,你后面怎么知道用字串拼接,前面不用啊Add('select dis_No from dish where dis_Name=’‘‘+disname+’’‘‘)
uj5u.com熱心網友回復:
adoquery1.Sql.Add('select dis_No from dish where dis_Name='''+ trim(disname)+''' ');
uj5u.com熱心網友回復:
sql陳述句寫法 有錯誤,另外臨時變數需要付賦初值。否則系統會付初值,影響資料比較結果。uj5u.com熱心網友回復:
應該是參考變數,出錯。支持5樓。uj5u.com熱心網友回復:
3樓+4樓的方法可以處理轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/64655.html
標籤:數據庫相關
