Y
ygzymw
Unregistered / Unconfirmed
GUEST, unregistred user!
保存代码如下,如果从表在保存时有重复键报错错,则修改从表再点保存,结果主表没有保存,从表保存上了,这是为什么呀??delphi7+sqlserver2000<br>procedure Tfrmcomdj.aSaveExecute(Sender: TObject);<br>begin<br> screen.Cursor:=crhourglass;<br> if dnlook.DataSource.DataSet.State in [dsinsert,dsedit] then<br> dnlook.DataSource.DataSet.Post;//主表<br> if dbgrid1.DataSource.DataSet.State in [dsinsert,dsedit] then<br> dbgrid1.DataSource.DataSet.post;//从表<br> if not DM.ADOConnection1.InTransaction then<br> begin<br> try<br> dm.ADOConnection1.BeginTrans;<br> (dnlook.DataSource.DataSet as tadoquery).UpdateBatch;//主表<br> (dbgrid1.DataSource.DataSet as tadoquery).UpdateBatch;//从表<br> dm.ADOConnection1.CommitTrans;<br> screen.Cursor:=crdefault;<br> CanSave := False;<br> //IniRecord;<br> except<br> on e: exception do<br> begin<br> application.MessageBox(pchar('Êý¾Ý±£´æʧ°Ü'+e.Message),'´íÎóÌáʾ',mb_ok+mb_iconerror);<br> dm.ADOConnection1.RollbackTrans;<br> screen.Cursor:=crdefault;<br> raise;<br> //dm.ADOConnection1.Cancel;<br><br> end<br> else<br> Application.MessageBox('·þÎñÆ÷æÇëÉÔºóÔÙÊÔ£¡','´íÎóÌáʾ',MB_OK+mb_iconWarning);<br> end;<br> end;<br> screen.Cursor:=crdefault;<br> end;