Allows to generate automatically single-table commands used to reconcile changes made to a
System.Data.DataSet with the associated database.
The following example uses
UniCommand, along with
UniDataAdapter and
UniConnection, to select rows from a database. 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 table. The example then creates a
UniCommandBuilder.
public DataSet SelectUniSrvRows(DataSet myDataSet,string myConnection,string mySelectQuery,string myTableName)
{
UniConnection myConn = new UniConnection(myConnection);
UniDataAdapter myDataAdapter = new UniDataAdapter();
myDataAdapter.SelectCommand = new UniCommand(mySelectQuery, myConn);
UniCommandBuilder myCommandBuilder = new UniCommandBuilder(myDataAdapter);
myConn.Open();
DataSet myDataSet = new DataSet();
myDataAdapter.Fill(myDataSet, "Departments");
//code to modify data in dataset here
//Without the UniCommandBuilder this line would fail
myDataAdapter.Update(myDataSet, "Departments");
myConn.Close();
return myDataSet;
}
Public Function SelectUniSrvRows(myDataSet As DataSet, myConnection As String, mySelectQuery As String, myTableName As String) As DataSet
Dim myConn As New UniConnection(myConnection)
Dim myDataAdapter As New UniDataAdapter()
myDataAdapter.SelectCommand = New UniCommand(mySelectQuery, myConn)
Dim myCommandBuilder As UniCommandBuilder = New UniCommandBuilder(myDataAdapter)
myConn.Open()
Dim myDataSet As DataSet = New DataSet
myDataAdapter.Fill(myDataSet, "Departments")
' Code to modify data in DataSet here
' Without the UniCommandBuilder this line would fail.
myDataAdapter.Update(myDataSet, "Departments")
myConn.Close()
SelectUniSrvRows = myDataSet
End Function