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

In This Topic
    DB2Error Class
    In This Topic
    Represents a DB2 error returned by the server.
    Syntax
    'Declaration
     
    Public Class DB2Error 
    public class DB2Error 
    Remarks
    Use this class in conjunction with DB2ErrorCollection and DB2Exception to obtain a DB2 error information. This class is often used when the user executes DML array binding operations to obtain multiply error information.
    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
       Devart.Data.DB2.DB2Error

    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