'aq是一个AdoQuery控件
sql:='select skills_index from prg_skills where skills_title=p1';
aq.SQL.Clear;
aq.SQL.Add(sql);
aq.Parameters.ParamByName('p1').Value:=txtTitle.Text;'程序运行到这一行出错
aq.Open;
出错信息:
Aq:Parameter 'p1' not found.
这是怎么回事啊?我在设计阶段为aq添加了参数(Parameters属性)没有任何作用,出现相同的错误。
如果aq没有参数,怎样给它添加参数啊?

解决方案 »

  1.   

    sql:='select skills_index from prg_skills where skills_title=:p1';
      

  2.   

    sql:='select skills_index from prg_skills where skills_title=:p1';
    aq.SQL.Clear;
    aq.SQL.Add(sql);
    aq.Parameters.ParamByName('p1').Value:=txtTitle.Text;
    aq.Open;
      

  3.   

    方法一:
     sql:='select skills_index from prg_skills where skills_title=:p1';
    ..........
    aq.Parameters.ParamByName('p1').Value:=txtTitle.Text;'方法二:
     sql:='select skills_index from prg_skills where skills_title='+txttitle.text;
    .................
    后面什么都不加了。
      

  4.   

    不好意思。
    是:
    aq.Parameters.ParamByName('p1').Value:=txtTitle.Text;'
    这句话就不写了。
      

  5.   

    点评一下你的代码:
    1 sql:='select skills_index from prg_skills where skills_title=p1';
    2 aq.SQL.Clear;
    3 aq.SQL.Add(sql);
    4 aq.Parameters.ParamByName('p1').Value:=txtTitle.Text;'程序运行到这一行出错
    5 aq.Open;帮你减少几行代码.
    1  aq.sql.text:='select skills_index from prg_skills where skills_title='+txttitle.text;
    2  aq.open;
    当然你最好是在OPEN的时候加上异常处理:
    try
      aq.open;
      ...
    except
      showmessage('连接失败!');
     ....
    end;
      aq.close;
      

  6.   

    sql:='select skills_index from prg_skills where skills_title=:p1';
    aq.SQL.Clear;
    aq.SQL.Add(sql);
    aq.Parameters.ParamByName('p1').Value:=txtTitle.Text;
    aq.Open;
      

  7.   

    :P1这样Delphi会给你自动创建参数列表的,而且还是命名参数
      

  8.   

    To:ltysunde(@ 为要饭而....呐喊 @) ,谢谢你的点评,主要是我的代码中参数有好多个,我的程序中当然有异常处理,我没帖出来罢了。多谢大家!问题解决了,马上结帖。