试试一下,如不对,贴出你的错误提示var
TimesInt: Integer;
begin
table1.open;
table1.first;
while (not table1.eof) do
begin
if check.Strings[0]=table1.fieldbyname('Zkzh').asstring then
begin
TimesInt:= table1.fieldByname('Time').AsInteger;
table1.FieldByName('Time').Value:=TimesInt+1;
Table1.Post;
Table1.Close;
Exit;
end;
end;
table1.append;
table1.FieldByName('Zkzh').Value:=check.strings[0];
table1.FieldByName('Xm').Value:=check.Strings[1];
table1.FieldByName('Send').Value:=check.Strings[3];
table1.FieldByName('receive').Value:=check.Strings[2];
table1.FieldByName('Time').Value:=1;
table1.FieldByName('filename').Value:=dir[i];
table1.Post;
table1.close;
end;
TimesInt: Integer;
begin
table1.open;
table1.first;
while (not table1.eof) do
begin
if check.Strings[0]=table1.fieldbyname('Zkzh').asstring then
begin
TimesInt:= table1.fieldByname('Time').AsInteger;
table1.FieldByName('Time').Value:=TimesInt+1;
Table1.Post;
Table1.Close;
Exit;
end;
end;
table1.append;
table1.FieldByName('Zkzh').Value:=check.strings[0];
table1.FieldByName('Xm').Value:=check.Strings[1];
table1.FieldByName('Send').Value:=check.Strings[3];
table1.FieldByName('receive').Value:=check.Strings[2];
table1.FieldByName('Time').Value:=1;
table1.FieldByName('filename').Value:=dir[i];
table1.Post;
table1.close;
end;
table1.Locate('ZKZH', check.Strings[0], []);
ishaveid:boolean;//是否有zkzh为id变量值的记录begin
ishaveid:=false;//没有table1.open;
while (not table1.eof) do
begin
if check.Strings[0]=table1.fieldbyname('Zkzh').asstring then
begin
ishaveid:=true;//有该id
break;
end;
end;if ishaveid then//有则改
begin
table1.edit;
table1.FieldByName('Time').Value:=table1.fieldByname('Time').AsInteger+1;
table1.post;
end
else
begin//无则加
table1.append;
table1.FieldByName('Zkzh').Value:=check.strings[0];
table1.FieldByName('Xm').Value:=check.Strings[1];
table1.FieldByName('Send').Value:=check.Strings[3];
table1.FieldByName('receive').Value:=check.Strings[2];
table1.FieldByName('Time').Value:=1;
table1.FieldByName('filename').Value:=dir[i];
table1.Post;
end;
table1.close;
end;
你的代码错在追加要用append,修改要用edit.是个低级错误。
table1.open;
table1.first;
while (not table1.eof) do
begin
if check.Strings[0]=table1.fieldbyname('Zkzh').asstring then
begin
if not (table1.state in [dsedit,dsInsert]) then table1.edit;
table1.FieldByName('Time').Value:=table1.fieldByname('Time').AsInteger+1;
table1.post;
break; end
else
table1.next;
end;
if table1.eof then
begin
table1.append;
table1.FieldByName('Zkzh').Value:=check.strings[0];
table1.FieldByName('Xm').Value:=check.Strings[1];
table1.FieldByName('Send').Value:=check.Strings[3];
table1.FieldByName('receive').Value:=check.Strings[2];
table1.FieldByName('Time').Value:=1;
table1.FieldByName('filename').Value:=dir[i];
table1.Post;
end;
table1.close;
table1 cannot edit?
其他幾位也都指出了你的錯誤