Error Trapping

In databinding, error trapping comes from two sources, error events or error objects.

Error Trapping via Error Events

Both the ADO Data Control and the RDO RemoteData Control data-source controls have error events. Typically you set an error event handler. The event handlers have the following signature.

void CMyDlg::OnErrorAdodc1(long ErrorNumber,
                           BSTR* FAR Description,
                           long Scode,
                            LPCTSTR Source,
                           LPCTSTR HelpFile,
                           long HelpContext,
                           BOOL FAR* fCancelDisplay)

Usually the Description field is populated, but the ErrorNumber and Scode fields are only populated in the event of COM errors. A standard event handler is to display the Description field in a message box. For example:

{
   USES_CONVERSION;   
// note: have to include the ATL file ATLConv.h to use the ATL conversion macros
   ::AfxMessageBox(OLE2T(*Description), MB_OK);
}

However, the ADO Data Control and RDO RemoteData Control are already set up to trap error events, so no coding is necessary.

Error Trapping via Error Objects

Both ADO and RDO have error objects. When generating wrapper classes, the RDO RemoteData Control generates wrappers for error objects, but ADO Data Control does not.

The ADO data Control automatically displays ADO error messages.

Back to Databinding with ActiveX Controls in Visual C++.