DynamicsCommandBuilder Class
Automatically generates single-table commands used to reconcile changes made to a
System.Data.DataSet with the Dynamics 365.
The following example uses
DynamicsCommand, along with
DynamicsDataAdapter and
DynamicsConnection, to select rows from Dynamics 365. The example is passed an initialized
System.Data.DataSet, a connection string, a query string that is SQL SELECT statement, and a string that is the name of the Dynamics 365 table. The example then creates a
DynamicsCommandBuilder.
public DataSet SelectDynamicsSrvRows(DataSet myDataSet,string dynamicsConnection,string mySelectQuery,string myTableName)
{
DynamicsConnection myConn = new DynamicsConnection(dynamicsConnection);
DynamicsDataAdapter myDataAdapter = new DynamicsDataAdapter();
myDataAdapter.SelectCommand = new DynamicsCommand(mySelectQuery, myConn);
DynamicsCommandBuilder dynamicsCommandBuilder = new DynamicsCommandBuilder(myDataAdapter);
myConn.Open();
DataSet myDataSet = new DataSet();
myDataAdapter.Fill(myDataSet, "Departments");
//code to modify data in dataset here
//Without the DynamicsCommandBuilder this line would fail
myDataAdapter.Update(myDataSet, "Departments");
myConn.Close();
return myDataSet;
}
Public Function SelectDynamicsSrvRows(myDataSet As DataSet, dynamicsConnection As String, mySelectQuery As String, myTableName As String) As DataSet
Dim myConn As New DynamicsConnection(dynamicsConnection)
Dim myDataAdapter As New DynamicsDataAdapter()
myDataAdapter.SelectCommand = New DynamicsCommand(mySelectQuery, myConn)
Dim dynamicsCommandBuilder As DynamicsCommandBuilder = New DynamicsCommandBuilder(myDataAdapter)
myConn.Open()
Dim myDataSet As DataSet = New DataSet
myDataAdapter.Fill(myDataSet, "Departments")
' Code to modify data in DataSet here
' Without the DynamicsCommandBuilder this line would fail.
myDataAdapter.Update(myDataSet, "Departments")
myConn.Close()
SelectDynamicsSrvRows = myDataSet
End Function
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2