Partager via


How to update Data Set from User Control?

How do update the Data Set for AxDataSource control by joining a new datasource in button_click() from c#?

Add a method on the DataSet in the AOT i.e. an X++ method called “modifyQuery”

Void modifyQuery()
{
querybuilddatasource qbds = someTable_q.datasourceName(someTable_ds.name());
qbds = qbds.adddatasource(tablenum(someOtherTable));
qbds.joinMode(JoinMode::ExistJoin);
qbds.relations(true);
someTable_ds.executeQuery();
}

Which implements the logic to add an extra query data source.

Then you can call this X++ method from the Update button in the managed code behind like this

protected void Button_Click(object sender, EventArgs e)
    {
        try
        {
            //Calling X++ method on the datset
            this.AxDataSource1.GetDataSet().DataSetRun.AxaptaObjectAdapter.Call("modifyQuery");
        }
        catch (System.Exception e)
        {
            if(!AxControlExceptionHandler.TryHandleException(this, e))
                throw;
        }
    }

 

Thanks Arif & Jeppe for the sample.

Comments