DBErrorCode method (DataWindows)
Description
Reports the database-specific error code that triggered the
DBError event.
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.
Controls
DataWindow type |
Method applies to |
---|---|
PowerBuilder |
DataWindow control, DataWindowChild object |
Syntax
[PowerBuilder]
1 |
long <span>dwcontrol</span><span>.</span><span>DBErrorCode </span>( ) |
Argument |
Description |
---|---|
dwcontrol |
A reference to a DataWindow control or |
Return Values
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:
1 |
dw_employee.<span>DBErrorCode</span>() |
Since this method is meaningful only in a DataWindow
DBError event, you can use the pronoun This instead
of the DataWindow’s name:
1 |
This.<span>DBErrorCode</span>() |
These statements check the error code for dw_employee
and if it is -4, perform some processing:
1 |
long ll_Error_Nbr |
1 |
ll_Error_Nbr = This.<span>DBErrorCode</span>() |
1 |
IF ll_Error_Nbr = <span>-</span> 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:
1 |
long ll_Error_Nbr |
1 |
1 |
ll_Error_Nbr = This.<span>DBErrorCode</span>() |
1 |
1 |
IF ll_Error_Nbr <> 0 THEN |
1 |
MessageBox("Database Error", "Number " & |
1 |
+ string(ll_Error_Nbr) + " " & |
1 |
+ This.DBErrorMessage(), StopSign!) |
1 |
// Stop PowerBuilder from displaying the error |
1 |
RETURN 1 |
1 |
END IF |