Return .Net DataTable using AX query


I’m working in AX 2009 and also ssrs reports 2008.

How to return .net datatable from X++ code?

Any suggestions are much appreciated. Thank you.

You can use .NET Interop for that. An example:

public System.Data.DataTable getTable()
    System.Data.DataTable dt = new System.Data.DataTable("My table");
    System.Data.DataColumnCollection columns = dt.get_Columns();
    System.Data.DataColumn idColumn;
    idColumn = new System.Data.DataColumn("ID", System.Type::GetType("System.Int32"));

    return dt;

Hi Martin,

Thanks for your response its worked for me.

Hi Martin ,

Thanks Its worked for me. I have another problem.

After deploying my report to SSRS its throwing error like CLRObject not initiated . because i am returning .Net Data Table.

Pls Suggest me the Solution,