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

Notifications

Announcements

No record found.

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
    237,880 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans