大哥:
我的代码如下,就是调试到table1.post出现提示“不能更新ID,字段不能更新“:
table1.DatabaseName:='yuan';
table1.TableName:='danxuan';
table1.Open;
table1.IndexFieldNames:='Knowledgepoint';
table1.First;
i:=1;
while (not table1.Eof) do
 begin
 if not(table1.State in [dsedit,dsInsert])then
 table1.Edit;
 table1.FieldByName('ID').Value:=i;
 table1.Post;
 i:=i+1;
 table1.Next;
 end;
 table1.Close;

解决方案 »

  1.   

    现在我加了一个允许为空的字段myid
    改为,但是执行后,这个myid字段有些记录的这个myid字段还是空的
    table1.DatabaseName:='yuan';
    table1.TableName:='danxuan';
    table1.Open;
    table1.IndexFieldNames:='Knowledgepoint';
    table1.First;
    i:=1;
    while (not table1.Eof) do
     begin
     if not(table1.State in [dsedit,dsInsert])then
     table1.Edit;
     table1.FieldByName('ID').Value:=i;
     table1.Post;
     i:=i+1;
     table1.Next;
     end;
     table1.Close;
      

  2.   

    这样做:
     while (not table1.Eof) do
     begin
       table1.Edit;
       table1.FieldByName('ID').Value:=i;
       table1.Post;
       i:=i+1;
       table1.Next;
     end;
      

  3.   

    为什么加了 if not(table1.State in [dsedit,dsInsert])then
    会不好用?
      

  4.   

    table1.DatabaseName:='yuan';
    table1.TableName:='danxuan';
    table1.active:=true;//一定要有這一句
    table1.Open;
    table1.IndexFieldNames:='Knowledgepoint';
    table1.First;
    i:=1;
    while (not table1.Eof) do
     begin
     if not(table1.State in [dsedit,dsInsert])then
     table1.Edit;
     table1.FieldByName('ID').Value:=i;
     table1.Post;
     i:=i+1;
     table1.Next;
     end;
     table1.Close;