各位前辈,我希望实现一个功能,选中dbgrid中的一行的时候,点击删除按纽就可以将其数据在控件中和数据库中删除掉。结果程序运行过程中系统报错’ADOTable:dataset not in edit or insert mode.‘process stopped.use step or run to continue.然后我继续点运行按纽,程序继续执行了,而且数据也都被删除掉了。我想知道为什么会报错啊?有什么方法可以避免啊?请各位高手指教!谢谢!
begin
try
adotable1.Edit;
DBGrid1.DataSource.DataSet.Delete;
dbgrid1.DataSource.DataSet.Post;
except
showmessage('error') ;
end;
end;
begin
try
adotable1.Edit;
DBGrid1.DataSource.DataSet.Delete;
dbgrid1.DataSource.DataSet.Post;
except
showmessage('error') ;
end;
end;
tryDBGrid1.DataSource.DataSet.Delete; //下面两句可以都不要
adotable1.Edit;
dbgrid1.DataSource.DataSet.Post; //删除操作完不能直接Postexcept
showmessage('error') ;
end;
end;
TRY
DBGRID1.DATASOURCE.DATASET.DELETE;
EXCEPT
MESSAGEBOX(FORM.HANDLE,'删除出错','警告',MB_OK+MB_ICONWARNING);
END;
END;你DELETE后,数据修改是直接提交了的,不需要在POST了.