所有的操作最好都用SQL来实现,你要面的的问题很多。

解决方案 »

  1.   

    1。可以用query来实现,不过我支持你用append或insert来实现。.2。该问题说的应该是说你的那段代码:
        databasename:=’c:’;
        tablename:=’renshi.dbf’;
        indexfieldnames:=’bianhao’;
       这段代码应该在table.close后再执行。
      

  2.   

    用TTable可以用Find去查是否有重复,当然用TQuery作比较好控制,下面是个小片段
    //如果stockinfos表里没有此'证券代码'、'申报代码'才会插入新记录
          with daqSCodeStockInfos do
          begin
            if Active then Close;
            SQL.Clear;
            SQL.Add(' select vc_stock_code from runbase..stockinfos');
            SQL.Add(' where vc_stock_code = ''' + sStockCode + '''');
            Open;
            First;
            if Eof then
            begin
              with daqStockInfos do
              try
                ParamByName('c_exchange').AsString := sExchange;
                ParamByName('vc_stock_code').AsString := sStockCode;
                ParamByName('vc_stock_name').AsString := sStockName;
                ParamByName('vc_report_code').AsString := sReportCode;            ExecSQL;
              except
                on E: Exception do MessageDlg( E.Message, mtWarning, [ mbOK ], 0 );
              end;
            end;//end..if not Locate('vc_stock_code')
            if Active then Close;
          end;//end..with daqSCodeStockInfos do
      

  3.   

    一般处理这种问题用下面的方法:procedure TForm1.Table1PostError(DataSet: TDataSet; E: EDatabaseError;
      var Action: TDataAction);
    begin
      //检测E就行了
    end;
      

  4.   

    一般处理这种问题用下面的方法:procedure TForm1.Table1PostError(DataSet: TDataSet; E: EDatabaseError;
      var Action: TDataAction);
    begin
      //检测E就行了
    end;
      

  5.   

    procedure TFyh.DBEdit7Exit(Sender: TObject);
    begin
    if Ammid_exist(trim(dbedit7.Text)) then
      begin
        showmessage('已有此编号!请重新输入!');
        dbedit7.SetFocus;
        exit;
      end;
    function tfyh.Ammid_exist(const Ammid:string):boolean;
    var
      amm:string;
    begin
      result:=false;
      amm:=trim(ammid);
      with dm.Qyh do
        begin
          close;
          sql.Clear;
          sql.Add('select Yh_ID from yh where trim(Amm_ID)='''+amm+'''');
          open;
          if recordcount>0 then
            begin
              result:=true;
              exit;
            end;
    //-------------------------------------------查A表------------------------
          close;
          sql.Clear;
          sql.Add('select Yh_ID from yh where trim(AmmB_ID)='''+amm+'''');
          open;
          if recordcount>0 then
            begin
              result:=true;
              exit;
            end;
    //----------------------------------------查B表----------------------------
          close;
          sql.Clear;
          sql.Add('select Yh_ID from yh where trim(AmmC_ID)='''+amm+'''');
          open;
          if recordcount>0 then
            begin
              result:=true;
              exit;
            end;
    //----------------------------------------查C表----------------------------    end;//with dm.qyh do