Represents a DB2 error returned by the server.
The following example generates
DB2Exception, containing
DB2ErrorCollection, due to inserting NULL values to NOT NULL columns. Then the example outputs
DB2Error messages to console.
|
|---|
DB2Connection connection = new DB2Connection("User ID=db2admin;Password=db2admin;Server=db2;Database=SAMPLE");
connection.Open();
try {
DB2Loader loader = new DB2Loader("DEPT", connection);
loader.Open();
loader.NextRow();
loader["DEPTNO"] = 111;
loader["DNAME"] = DBNull.Value; // database field cannot contain NULL values
loader["LOC"] = "NEW YORK";
loader.NextRow();
loader["DEPTNO"] = 1;
loader["DNAME"] = DBNull.Value; // database field cannot contain NULL values
loader["LOC"] = "CHICAGO";
loader.NextRow();
loader["DEPTNO"] = 2;
loader["DNAME"] = DBNull.Value; // database field cannot contain NULL values
loader["LOC"] = "DALLAS";
loader.Close();
}
catch (DB2Exception ex) {
foreach (DB2Error error in ex.Errors) {
Console.WriteLine("Message: " + error.Message + Environment.NewLine +
"Native: " + error.NativeError.ToString() + Environment.NewLine +
"Source: " + error.Source);
}
} |
|
|---|
Dim connection As New DB2Connection("User ID=db2admin;Password=db2admin;Server=db2;Database=SAMPLE")
connection.Open()
Try
Dim loader As New DB2Loader("DEPT", connection)
loader.Open()
loader.NextRow()
loader("DEPTNO") = 111
loader("DNAME") = DBNull.Value
' database field cannot contain NULL values
loader("LOC") = "NEW YORK"
loader.NextRow()
loader("DEPTNO") = 1
loader("DNAME") = DBNull.Value
' database field cannot contain NULL values
loader("LOC") = "CHICAGO"
loader.NextRow()
loader("DEPTNO") = 2
loader("DNAME") = DBNull.Value
' database field cannot contain NULL values
loader("LOC") = "DALLAS"
loader.Close()
Catch ex As DB2Exception
For Each [error] As DB2Error In ex.Errors
Console.WriteLine((("Message: " + [error].Message _
+ Environment.NewLine & "Native: " & [error].NativeError.ToString()) _
+ Environment.NewLine & "Source: ") + [error].Source)
Next
End Try |
System.Object
Devart.Data.DB2.DB2Error