DBErrorCode

Description

Reports the database-specific error code that triggered the DBError event.

NoteObsolete method DBErrorCode is obsolete and will be discontinued in the future. You should replace all use of DBErrorCode as soon as possible. The database error code is available as an argument in the DBError event.

Applies to

DataWindow type

Method applies to

PowerBuilder

DataWindow control, DataWindowChild object

Syntax

PowerBuilder

long dwcontrol.DBErrorCode ( ) 

Argument

Description

dwcontrol

A reference to a DataWindow control or child DataWindow

Returns

Returns an error code when a database error occurs in dwcontrol. Error codes –1 through –4 are PowerBuilder codes. Other codes are database-specific. Returns 0 if there is no error.

If dwcontrol is null, the method returns null.

PowerBuilder error codes are:

Usage

When a database error occurs while a DataWindow control is interacting with the database, PowerBuilder triggers the DBError event. Since DBErrorCode is meaningful only if a database error has occurred, you should call this method only in the DBError event.

Examples

Example 1

This statement returns the error code for dw_employee:

dw_employee.DBErrorCode()

Example 2

Since this method is meaningful only in a DataWindow DBError event, you can use the pronoun This instead of the DataWindow’s name:

This.DBErrorCode()

Example 3

These statements check the error code for dw_employee and if it is -4, perform some processing:

long ll_Error_Nbr

ll_Error_Nbr = This.DBErrorCode()

IF ll_Error_Nbr =  - 4 THEN ...

Example 4

When an error occurs in dw_Emp, the following statements in the DBError event’s script will display the error number and message. A return code of 1 suppresses the default error message:

long ll_Error_Nbr


ll_Error_Nbr = This.DBErrorCode()


IF ll_Error_Nbr <> 0 THEN

		MessageBox("Database Error", "Number " &

		+ string(ll_Error_Nbr) + " " &

		+ This.DBErrorMessage(), StopSign!)

		// Stop PowerBuilder from displaying the error

		RETURN 1

END IF

See also