Ian,
You should wrap your delete in a transaction. That way if something does =
work, you will be able to recover from it and rollback the statement
Regards,
Willie
oDataConn:BeginTrans()
oCommand :=3DAdoCommand{}
oCommand:ActiveConnection :=3DoDataConn
oCommand:CommandText :=3DcSql
oCommand:CommandType :=3DadCmdText
oCommand:CommandTimeout :=3D0
oRS =
:=3DoCommand:Execute(@[EMAIL PROTECTED]
)
oDataConn:CommitTrans()
oRS :=3Dnull_object
oCommand :=3Dnull_object
lResult :=3Dtrue
ErrorBlock(cbErr)
RECOVER USING uError
oDataConn:RollBackTrans()
ErrorBlock(cbErr)
IF IsObject(uError)
cErrMsg :=3D "SQLConnection:ExecCommand Statement Error : " =
+
uError:Description +
CRLF + "Delete Instruction Failed"
ELSEIF IsString(uError)
cErrMsg :=3D uError + CRLF + "Delete Instruction Failed"
ENDIF
ErrorBox{,cErrMsg}:show()
END SEQUENCE
return nRecords
"Ian" <ithomson@[EMAIL PROTECTED]
> wrote in message =
news:9c3ed7e5-c8ba-4f4d-935b-dd62b98db5be@[EMAIL PROTECTED]
> Hi Willie,
>=20
> I took your advice about cascading deletes and set up my tables
> accordingly. Having tested this it works a treat but can you clarify
> one thing for me.
>=20
> The code I use is below
>=20
> lOCAL nRecords as LONG
> lOCAL oRS as ADORecordset
> lOCAL oCommand as ADOCommand
> lOCAL cbErr as CODEBLOCK
> local lResult :=3Dfalse as logic
> locAL uError as USUAL
> local cErrMsg as string
>=20
> cbErr :=3D ErrorBlock({|oErr|_Break(oErr)})
>=20
> BEGIN SEQUENCE
> oCommand :=3DAdoCommand{}
> oCommand:ActiveConnection :=3DoDataConn
> oCommand:CommandText :=3DcSql
> oCommand:CommandType :=3DadCmdText
> oCommand:CommandTimeout :=3D0
> oRS :=3DoCommand:Execute(@[EMAIL PROTECTED]
)
> oRS :=3Dnull_object
> oCommand :=3Dnull_object
> lResult :=3Dtrue
> ErrorBlock(cbErr)
> RECOVER USING uError
> ErrorBlock(cbErr)
> IF IsObject(uError)
> cErrMsg :=3D "SQLConnection:ExecCommand Statement Error : " +
> uError:Description +
> CRLF + "Delete Instruction Failed"
> ELSEIF IsString(uError)
> cErrMsg :=3D uError + CRLF + "Delete Instruction Failed"
> ENDIF
> ErrorBox{,cErrMsg}:show()
> END SEQUENCE
> return nRecords
>=20
> If there are twenty records in the details file but only ten can be
> deleted for whatever reason, will this leave all twenty records intact
> or do I have to do some kind of rollback to recover the ten that were
> deleted.
>=20
> ie If it can not delete all twenty detail records it should not delete
> any.
>=20
> Regards,
> Ian


|