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;

解决方案 »

  1.   

    adoquery1.Sql.Add('select dis_No from dish where dis_Name='+quotedstr(disname));
      

  2.   

    select dis_No from dish where dis_Name=‘‘disname’’
      

  3.   

    //---------------------------------------   
    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#的替换下
    倒数第一行和倒数第二行交换一下。
      

  4.   

    参数disname不能直接在字符串引号‘’中间直接用,你后面怎么知道用字符串拼接,前面不用啊
    Add('select dis_No from dish where dis_Name=’‘‘+disname+’’‘‘)
      

  5.   


      adoquery1.Sql.Add('select dis_No from dish where dis_Name='''+ trim(disname)+''' ');
      

  6.   

    sql语句写法 有错误,另外临时变量需要付赋初值。否则系统会付初值,影响数据比较结果。