dotConnect for DB2 Documentation
Devart.Data.DB2 Namespace / DB2ErrorCollection Class
Members Example

In This Topic
    DB2ErrorCollection Class
    In This Topic
    Collects errors of an exception generated by dotConnect for DB2.
    Syntax
    Remarks
    This class is created by DB2Exception to collect instances of the DB2Error class. DB2ErrorCollection always contains at least one instance of the DB2Error class. This class is often used when a user executes DML array binding operations to obtain detailed information in case of multiple errors.
    Example
    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
    Inheritance Hierarchy

    System.Object
       System.Collections.CollectionBase
          Devart.Data.DB2.DB2ErrorCollection

    Requirements

    Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also