Thursday, July 30, 2015

AX 2012 AX 2009 Execute SQL Statement AX2012 AX2009


   To execute the Sql statement in x++, create the job or class with following code

    Connection connection;
    Statement  statement;
    str        sql;
    ResultSet  resultSet;
    SqlStatementExecutePermission perm;
    connection = new Connection();

    sql = "SELECT * FROM CUSTTABLE";
    perm = new SqlStatementExecutePermission(sql);
    perm.assert();
    statement = connection.createStatement();
    resultSet = statement.executeQuery(sql);
    while(resultSet.next())
    {
         info(resultSet.getString(1));
    }
    // End the scope of the assert call.
    CodeAccessPermission::revertAssert();


 And then create action menu item to execute the sql statement.

Thanks,
K. Arunsubramaniam



No comments:

Post a Comment