用adoquery,做sql查询
delete from table where 区号=:qh
可是在程序执行时提示“无返回值。“,然后中断,必须再次运行。
该如何阻止它弹出异常对话框????

解决方案 »

  1.   

    try
      adoquery.ExecSQL
    except
    end
      

  2.   

    用Applicationevents控件,在好象是EXCEPTION事件里加你自己想要的异常处理。这样就不会弹出原来的异常对话框。
      

  3.   

    同意qiujsh(qiujsh) 我想你一定是用了open 改为adoquery.execsql就可以了
      

  4.   

    DataModule1.ADOQuery_fw.Close;
    DataModule1.ADOQuery_fw.SQL.Clear;
    DataModule1.ADOQuery_fw.Parameters.Items[0].Value:=MEdit_qzh.Text;
    DataModule1.ADOQuery_fw.SQL.Add('delete from unit_house where 区座号=:qzh');
    DataModule1.ADOQuery_fw.ExecSQL;
    我用的是sql server 2000,运行后错误消息如下::
    project P_mainfrm.exe raised exception class ElistError with message
    'list index out of bounds(0)'.Process stopped救我丫!!!
      

  5.   

    你有一个list对象和数据源关联吧
    由于这种命令不返回数据
    这样就会清空数据集
    我觉得使用这种命令时使用一个新的adoquery或者是命令对象单独执行
    然后再刷新数据源就可以了
      

  6.   

    我没有使用list丫,只是用了ComboBox,DBGrid, DateTimePicker,MEdit
    而且都没有连接数据源,只有DBGrid连接了数据源。
    每个控件都是过了,还是project P_mainfrm.exe raised exception class ElistError with message
    'list index out of bounds(0)'.Process stopped
      

  7.   

    如果没有返回值的...要用execsql不然会出错..
      

  8.   

    数据库异常状态:
    A complete listing of the database errorcodes is found in the
      DBIErrs.Int file in the Delphi/Doc directory or in the IDAPI.h
      file in the Borland Database Engine.  Database errors are defined by category and code. Here's a sample:{ ERRCAT_INTEGRITY }  ERRCODE_KEYVIOL               = 1;  { Key violation }
      ERRCODE_MINVALERR             = 2;  { Min val check failed }
      ERRCODE_MAXVALERR             = 3;  { Max val check failed }
      ERRCODE_REQDERR               = 4;  { Field value required }
      ERRCODE_FORIEGNKEYERR         = 5;  { Master record missing }
      ERRCODE_DETAILRECORDSEXIST    = 6;  { Cannot MODIFY or DELETE this Master record }
      ERRCODE_MASTERTBLLEVEL        = 7;  { Master Table Level is incorrect }
      ERRCODE_LOOKUPTABLEERR        = 8;  { Field value out of lookup tbl range }
      ERRCODE_LOOKUPTBLOPENERR      = 9;  { Lookup Table Open failed }
      ERRCODE_DETAILTBLOPENERR      = 10; { 0x0a Detail Table Open failed }
      ERRCODE_MASTERTBLOPENERR      = 11; { 0x0b Master Table Open failed }
      ERRCODE_FIELDISBLANK          = 12; { 0x0c Field is blank }
      The constant for the base category is added to these constants to represent
      a unique DBI errorcode;  DBIERR_KEYVIOL  = (ERRBASE_INTEGRITY + ERRCODE_KEYVIOL);
      DBIERR_REQDERR = (ERRBASE_INTEGRITY + ERRCODE_REQDERR);
      DBIERR_DETAILRECORDSEXIST = (ERRBASE_INTEGRITY + ERRCODE_DETAILRECORDSEXIST);
      DBIERR_FORIEGNKEYERR = (ERRBASE_INTEGRITY + ERRCODE_FORIEGNKEYERR);  The ERRBASE_INTEGRITY value is $2600 (Hex 2600) or 9728 decimal.
      Thus, for example, the errorcode for keyviol is 9729
                                       for master with details is 9734.
    开头加上:
    const
      eKeyViol = 9729;
      eRequiredFieldMissing = 9732;
      eForeignKey = 9733;
      eDetailsExist = 9734;implementation1、主从表删主表(无级联删除情况)
    procedure Tdatamodule1.table1DeleteError(Dataset:Tdataset;E:EDatabaseError;var Action:TdataAction);
    begin
    if (E is EDBEngineError) then 
      if (E as EDBEngineError).Error[0].Errorcode=eDetailsExist then 
      begin
        messageDLG('请先删除从表的相关的记录!',mtWarning,[mbOK],0);
        abort;
      end;
    end;
    2、主关键字重复
    procedure Tdatamodule1.table1PostError(Dataset:Tdataset;E:EDatabaseError;var Action:TdataAction);
    begin
    if (E is EDBEngineError) then 
      if (E as EDBEngineError).Error[0].Errorcode=eKeyViol then 
      begin
        messageDLG('主关键字重复!已经存在该编号!',mtWarning,[mbOK],0);
        abort;
      end;
    end;
    3、关键字重复和关键字为空的情况
    procedure Tdatamodule1.table1PostError(Dataset:Tdataset;E:EDatabaseError;var Action:TdataAction);
    var Error:integer;
    begin
    if (E is EDBEngineError) then 
    begin
      Error:= (E as EDBEngineError).Errors[0].Errorcode; 
      case Error of 
        eRequiredFieldMissing:    //关键字为空  
          begin
            messageDLG('主关键字不能为空!',mtWarning,[mbOK],0);
            Abort;
          end;
        eKeyViol:    //关键字已经存在  
          begin
            messageDLG('主关键字重复!已经存在该编号!',mtWarning,[mbOK],0);
            Abort;
          end;
       end;
    end;
    end;beforepost过程中的验证:
    table1.fieldbyname('name').focuscontrol;
    raise Exception.create(table1.fieldbyname('name').displaylabel+'错误');
      

  9.   

    我觉得很正常哈 两个 ado组件
    一个是主的用于连接数据源,向用户提供数据
    另一个辅助,专门执行那些没有返回的命令,这个是不用连接数据源的
     这样的好处就是数据显示不会断,比如你就使用主ado执行没有返回的命令
    那么数据控件中的对象是要清空的,你还得再次执行来显示数据
    辅助的用execsql
      

  10.   

    try
      adoquery.ExecSQL
    except
    end
      

  11.   

    DataModule1.ADOQuery_fw.Close;
    DataModule1.ADOQuery_fw.SQL.Clear;
    DataModule1.ADOQuery_fw.Parameters.Items[0].Value:=MEdit_qzh.Text;//出错是这这行此时没有Parameters.Items[0]
    DataModule1.ADOQuery_fw.SQL.Add('delete from unit_house where 区座号=:qzh');
    DataModule1.ADOQuery_fw.Parameters.Items[0].Value:=MEdit_qzh.Text;//应放在这里!
    DataModule1.ADOQuery_fw.ExecSQL;
      

  12.   

    我的问题解决了!谢谢jixinfa(DELHPI程序员) !
    还有个问题:做了删除delete后,我的DBGrid中的数据不能显示删除后的数据表!
    我该如个刷新呢???