How to Use DictTable in Connection Using X++ in Ax 2012

Description:- The Connection class establishes a current database session that you can use to execute SQL statements and return results. In the following example, the create Statement method initializes the Statement object. The Statement.executeQuery method executes an SQL statement and then stores the retrieved data in the ResultSet object. The Dict Table class provides information about a table. How to create an instance of the Dict Table class to determine whether the data in the table is stored on a per-company basis. 

Create job and Run.

static void ODBCConnectionDictTable(Args _args)
{
    DictTable  _dictTable;
    Connection  con;
    Resultset       resultSet;
    Statement       statement;
    SqlStatementExecutePermission   sqlpermission;
    str Query;  

    _dictTable = new DictTable(tableNum(TableName));
    if(_dictTable != null)
    {
        con = new Connection();
        if (con)
        {
            Query=strfmt( "Select * from %1",_dictTable.name(DbBackend::Sql));
            //Assert permission for executing the sql string.
            sqlpermission = new SqlStatementExecutePermission(Query);
            sqlpermission.assert();
            // Create new Statement instance
            statement =con.createStatement();
            resultSet =statement.executeQuery(Query);
            while(resultSet.next())
            {
                info(resultSet.getString(1));
            }
        }
        else
        {
            error("Failed to log on to the database through ODBC.");
        }
    }
}

Related Posts

Previous
Next Post »

Thanks for comments.....