是这样的,我有一个问题我创建了一个临时表temp,我用update向里面更新数据。
可是发现有一些问题请大家看一下!  query1.Close;
       query1.sql.Clear;
       query1.sql.add('update temp set temp.income_num=(select sum(book_total) from income_book where income_book.book_num=temp.book_num)');       query1.execsql;
end;
   在这里where有错误,其他应设有问题 ,显示错误请大家庭看一下!
   key violation   操作必须有一个可更新的的查询,
大家看一下我用的temp是一个临时表。环境地是access2000

解决方案 »

  1.   

    临时表temp定义一个关键字,不行就得改为固定表。
      

  2.   

    对我说一下,怎么做呢!      with table1 do
      begin
        Active := False;  { The Table component must not be active }
        { First, describe the type of table and give it a name }
        DatabaseName := '6';
        TableType := ttparadox;
        TableName := 'temp';
        { Next, describe the fields in the table }
        with FieldDefs do
        begin
          Clear;
          Add('book_num', ftstring, 4, True);
          Add('book_name', ftString, 4, true);
          Add('book_price', ftcurrency, 0, true);
          Add('book_year', ftInteger, 0, true);
          Add('book_month', ftinteger, 0, true);
          Add('income_num', ftinteger, 0, true);
          Add('outcome_num', ftinteger, 0, true);
          Add('lastmonth_num', ftinteger, 0, true);
          Add('thismonth_num', ftinteger, 0, true);
        end;
        { Next, describe any indexes }
        with IndexDefs do
        begin
          Clear;
          { The first index has no name because it is a Paradox primary key }
         // Add('', 'book_num', [ixPrimary, ixUnique]);
         // Add('Fld2Indx', 'book_num', [ixCaseInsensitive]);
         table1.indexdefs:=table2.indexdefs;
       end;
    下面是临时表好象生成的时候就没有关键字,请你对我说一下如何处理这个问题。key 为book_num
      

  3.   

    query1.Close;
           query1.sql.Clear;
           query1.sql.add('insert into temp (income_num) select sum (book_total)         from income_book ');       query1.execsql;
      

  4.   

    你为什么不用插入语句
     INSERT INTO TABLENAME VALUES(‘’,‘’)