SugarCommandBuilder Class
Automatically generates single-table commands used to reconcile changes made to a
System.Data.DataSet with the SugarCRM.
The following example uses
SugarCommand, along with
SugarDataAdapter and
SugarConnection, to select rows from SugarCRM. 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 SugarCRM table. The example then creates a
SugarCommandBuilder.
public DataSet SelectSugarSrvRows(DataSet myDataSet,string sugarConnection,string mySelectQuery,string myTableName)
{
SugarConnection myConn = new SugarConnection(sugarConnection);
SugarDataAdapter myDataAdapter = new SugarDataAdapter();
myDataAdapter.SelectCommand = new SugarCommand(mySelectQuery, myConn);
SugarCommandBuilder sugarCommandBuilder = new SugarCommandBuilder(myDataAdapter);
myConn.Open();
DataSet myDataSet = new DataSet();
myDataAdapter.Fill(myDataSet, "Departments");
//code to modify data in dataset here
//Without the SugarCommandBuilder this line would fail
myDataAdapter.Update(myDataSet, "Departments");
myConn.Close();
return myDataSet;
}
Public Function SelectSugarSrvRows(myDataSet As DataSet, sugarConnection As String, mySelectQuery As String, myTableName As String) As DataSet
Dim myConn As New SugarConnection(sugarConnection)
Dim myDataAdapter As New SugarDataAdapter()
myDataAdapter.SelectCommand = New SugarCommand(mySelectQuery, myConn)
Dim sugarCommandBuilder As SugarCommandBuilder = New SugarCommandBuilder(myDataAdapter)
myConn.Open()
Dim myDataSet As DataSet = New DataSet
myDataAdapter.Fill(myDataSet, "Departments")
' Code to modify data in DataSet here
' Without the SugarCommandBuilder this line would fail.
myDataAdapter.Update(myDataSet, "Departments")
myConn.Close()
SelectSugarSrvRows = myDataSet
End Function