web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Creating System.Data.DataSet in MS Dynamics AX

(0) ShareShare
ReportReport
Posted on by 1,650

Hello together,

currently I'm trying to integrate a .NET control into MS Dynamics AX 2012. In order to display the values. The control needs a certain .NET DataSet (System.Data.DataSet) to be passed.

Are there any good examples how I could create a DataSet within x++ and fill it with data?

I found a Job the data could be read from a XML file but unfortunately I don’t get any response:

static void TestDOTNETDataSet(Args _args)

{

    System.Data.DataSet                 DataSet;

    System.Data.DataTableCollection     DataTableCollection ;

    System.Data.DataTable               DataTable;

    System.Data.DataRowCollection       DataRowCollection;

    System.Data.DataColumnCollection    DataColumnCollection;

    System.Data.DataRow                 DataRow;

    System.Data.DataColumn              DataColumn;

    int                                 i,j,TotalCol,TotalRow;

    str                                 _xml;

    ;

 

    DataSet                 = new System.Data.DataSet();

    DataSet.ReadXml(@"C:\Data.xml", System.Data.XmlReadMode::ReadSchema);

    DataTableCollection     = DataSet.get_Tables();

    DataTable               = DataTableCollection.get_Item(0);

    DataColumnCollection    = DataTable.get_Columns();

    DataRowCollection       = DataTable.get_Rows();

    TotalRow                = DataRowCollection.get_Count();

    TotalCol                = DataColumnCollection.get_Count();

 

 

    for(i = 0; i < TotalRow; i ++)

    {

        DataRow = DataRowCollection.get_Item(i);

        //setprefix(CLRInterop::getAnyTypeForObject(DataRow.get_Item(i)));

        for(j = 0; j < TotalCol; j ++)

        {

            //DataRow = DataRowCollection.get_Item(i);

            if (DataRow.IsNull(j))

                _xml = 'null';

            else

                _xml = DataRow.get_Item(j);

            info(strfmt("%1 - %2 - %3",i,j,_XML));

        }

    }

}

Furthermore this solution would imply, that I have to write the data from AX-Tables into an XML-File, which would be “double work”. I would prefer to create / write the dataset directly in AX.

Any help would be appreciated.

Thanks in advance

Sebastian

 

*This post is locked for comments

I have the same question (0)
  • overzke Profile Picture
    5 on at

    //读取字符串中的信息
    StrStream = new System.IO.StringReader(_xml);
    //获取StrStream中的数据
    Xmlrdr = new System.Xml.XmlTextReader(StrStream);
    //ds获取Xmlrdr中的数据
    _DataSet.ReadXml(Xmlrdr);

  • Verified answer
    Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at

    You'll find many examples as soon as you realize that System.Data is a .NET library, therefore you'll find much more stuff if you look for .NET code and not just for X++. It's possible to use it in X++ through .NET Interop, although writing it in C#, encapsulating in a custom .NET library and using this library from X++ would be easier. You wouldn't have to translate .NET code to X++.

    If you decide to do it in X++ anyway, this is a snippet of how it will look like (not tested):

    System.Data.DataTable table1 = new System.Data.DataTable('Table1');
    System.Data.DataColumn column1 = new System.Data.DataColumn('Field1', System.Type::GetType('System.String'));
    System.Data.DataColumnCollection columnCollection = table1.get_Columns();
    System.Data.DataRow dataRow;
        
    column1.set_DefaultValue('');
    columnCollection.Add(column1);
        
    dataRow = table1.NewRow();
    dataRow.set_Item('Field1', 'abcd');
  • dolee Profile Picture
    11,279 on at

    Hi Sebastian,

    Brainstorming here...

    Write managed code to do the work and returns a System.Data.DataSet?

    So it ends up like:

      DataSet = myLibrary.getAXTableDataSet();

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Andrew Jones a1x Profile Picture

Andrew Jones a1x 2

#3
GL-01081504-0 Profile Picture

GL-01081504-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans