Sirus
Sirus

Reputation: 502

Creating a DataTable in X++

I'm trying to create a datatable in microsoft ax x++.

I need to return some information back to a webservice. Problem is i'm having trouble getting this code to work. it runs to the point where i try to add a column because apparently that function doesn't work....

Does anyone have the code in full to create a datatable in x++. this code works up until the column code.. because basically what i'm doing is query some information and returning it back to a webservice.. unless theres another way to return multiple information back to a webservice that uses c#

System.Data.DataTable dt = new System.Data.DataTable("MyTable"); 
System.Data.DataColumnCollection columns = dt.get_Columns();
System.Data.DataColumn ProductName;
System.Data.DataColumn QtyOrdered;
System.Data.DataColumn ProductID;
System.Data.DataRow row;

ProductID = new System.Data.DataColumn("ProductID", System.Type::GetType("System.Int32"));
ProductName = new System.Data.DataColumn("ProductName", System.Type::GetType("System.String"));
QtyOrdered = new System.Data.DataColumn("QtyOrdered", System.Type::GetType("System.String"));      
//   dt.Columns.Add(ProductID);
//   dt.Columns.Add(ProductName);
//   dt.Columns.Add(QtyOrdered);    
row=dt.NewRow();

Upvotes: 1

Views: 2107

Answers (1)

10p
10p

Reputation: 6706

Did you try replacing lines

//    dt.Columns.Add(ProductID);
//    dt.Columns.Add(ProductName);
//    dt.Columns.Add(QtyOrdered);

with

    columns.Add(ProductID);
    columns.Add(ProductName);
    columns.Add(QtyOrdered);

?

P.S. To populate the row:

    System.Data.DataRowCollection rows = dt.get_Rows();

    ...

    row = dt.NewRow();
    row.set_Item("ProductID", 1);
    row.set_Item("ProductName", "PN");
    row.set_Item("QtyOrdered", "QO");

    rows.Add(row);

I suggest you to read some MSDN articles such as .NET Interop from X++, How To Use X++ Syntax for CLR Arrays, etc. - it should help you understand how to use .NET assemblies from X++.

Upvotes: 1

Related Questions