DBErrorCode (obsolete)

Description

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

Obsolete 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


Return value

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:

  • -1  Can't connect to the database because of missing values in the transaction object.

  • -2  Can't connect to the database.

  • -3  The key specified in an Update or Retrieve no longer matches an existing row. (This can happen when another user has changed the row after you retrieved it.)

  • -4  Writing a blob to the database failed.

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

This statement returns the error code for dw_employee:

dw_employee.DBErrorCode()

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()

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 ...

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

DBErrorMessage