DB2 10.5 for Linux, UNIX, and Windows

DB2Error.SQLState Property

Gets the five-character error code that follows the ANSI SQL standard for the database.

Namespace:
IBM.Data.DB2
Assembly:
IBM.Data.DB2 (in IBM.Data.DB2.dll)

Syntax

[Visual Basic]
<Serializable>
Public ReadOnly Property SQLState As String
[C#]
[Serializable]
public string SQLState {get;}
[C++]
[Serializable]
public: __property String* get_SQLState();
[JScript]
public
   Serializable
function get SQLState() : String;

Property value

The five-character error code, which identifies the source of the error if the error can be issued from more than one place.

Example

[Visual Basic, C#] The following example displays the properties of the DB2®Error .

[Visual Basic]
Public Sub DisplayDB2ErrorCollection(myException As DB2Exception)
    Dim i As Integer
    For i = 0 To myException.Errors.Count - 1
        MessageBox.Show("Index #" + i.ToString() + ControlChars.Cr _
           + "Message: " + myException.Errors(i).Message + ControlChars.Cr _
           + "Native: " + myException.Errors(i).NativeError.ToString() 
                        + ControlChars.Cr _
           + "Source: " + myException.Errors(i).Source + ControlChars.Cr _
           + "SQL: " + myException.Errors(i).SQLState + ControlChars.Cr)
    Next i
End Sub

[C#]
public void DisplayDB2ErrorCollection(DB2Exception myException)
{
   for (int i=0; i < myException.Errors.Count; i++)
   {
      MessageBox.Show("Index #" + i + "\n" +
             "Message: " + myException.Errors[i].Message + "\n" +
             "Native: " + myException.Errors[i].NativeError.ToString() + "\n" +
             "Source: " + myException.Errors[i].Source + "\n" +
             "SQL: " + myException.Errors[i].SQLState + "\n");
   }
}