Click to Rate and Give Feedback
MSDN
MSDN Library
Microsoft Dynamics
Reference
Classes
Statement Class
 Statement.getLastError Method
Collapse All/Expand All Collapse All
Microsoft Dynamics AX 2009
Statement.getLastError Method

Retrieves the error code returned by the SQL database backend for the last SQL operation.

public int getLastError()

Called

The error code returned by the SQL database backend for the last SQL operation; or 0 for success.

static void StatementGetLastError() 
{
    str sql, sql2;
    UserConnection Connection = new UserConnection();
    Statement Statement = Connection.createStatement();
    boolean clear_infolog = false;

    print "-Delete-a-non-existing-record-(valid statement)-----------";
    sql = "delete from zipcode where Recid = 2";
    new SqlStatementExecutePermission(sql).assert();

    Statement.executeUpdate(sql);
    print " Error code was: ", Statement.getLastError();
    print " Error message was '", Statement.getLastErrorText(), "'";

    try
    {
        print "\n";
        print "-Delete-from-a-non-existing-table-(invalid statement)---    --";
        sql2 = "delete from StrangeTable07";
        new SqlStatementExecutePermission(sql2).assert();
        Statement.executeUpdate(sql2);
    }
    catch (exception::Error)
    {
        print "Exception was caught:";
        print " Error code was: ", Statement.getLastError();
        print " Error message was '", Statement.getLastErrorText(), "'";
    }
    
    CodeAccessPermission::revertAssert();
    pause;
}
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker