Retrieving Data into DataSets

The mmBusinessObject class (and in turn all of your application-level business objects) has two main methods that can be used for retrieving data into typed or untype DataSets. These methods are GetDataSet() and FillDataSet().

Specifying Stored Procedures or Dynamic SQL

GetDataSet() and FillDataSet() can retrieve data using stored procedures or parameterized queries. The business object's DefaultCommandType property (usually set at the ABusinessObject level) determines whether the command string passed to these methods is a stored procedure name or a dynamic SQL string. Alternately, you can specify the command type by using one of the GetDataSet() or FillDataSet() overloads that accepts a commandType parameter.

Deciding Whether to use GetDataSet() or FillDataSet()

GetDataSet() should be used when you want to create a new DataSet and fill it with a new DataTable. FillDataSet() should be used when you want to add a DataTable to an existing DataSet. This ability to add a DataTable to an existing DataSet comes in handy when you need to have multiple DataTables in a single DataSet. Using FillDataSet() allows you to leave existing DataTables intact while adding a new DataTable. If you want to play it safe, always use FillDataSet() rather than GetDataSet().

Using Typed DataSets

By defaultGetDataSet() and FillDataSet() store retrieved data into an untyped DataSet. If you override the business object's CreateDataSet method you can also fill a typed DataSet.

GetDataSet

Here is the description and signature of the GetDataSet overloads.

  • Returns a new, untyped DataSet with the specified table containing the results of the command string (based on command type) w/ parameters executed against the specified database.

    protected virtual DataSet GetDataSet(string command, string tableName, string databaseKey,
    	CommandType cmdType, params IDbDataParameter[] dataParams)

  • Returns a new, untyped DataSet with the specified table containing the results of the command string (based on command type) w/ parameters executed against the default database.

    protected virtual DataSet GetDataSet(string command, string tableName, CommandType cmdType,
    	params IDbDataParameter[] dataParams)

  • Returns a new, untyped DataSet with the default table containing the results of the command string (based on command type) w/ parameters executed against the default database.

    protected virtual DataSet GetDataSet(string command, CommandType cmdType,
    	params IDbDataParameter[] dataParams)

  • Returns a new, untyped DataSet with the specified table containing the results of the command string w/ parameters executed against the specified database.

    protected virtual DataSet GetDataSet(string command, string tableName, string databaseKey,
    	params IDbDataParameter[] dataParams)

  • Returns a new, untyped DataSet with the specified table containing the results of the command string w/ parameters executed against the default database

    protected virtual DataSet GetDataSet(string command, string tableName,
    	params IDbDataParameter[] dataParams)

  • Returns a new, untyped DataSet with the default table containing the results of the command string w/ parameters executed against the default database.

    protected virtual DataSet GetDataSet(string command, params IDbDataParameter[] dataParams)
    

  • Returns a new, untyped DataSet with the specified table containing the results of the command string executed against the specified database.

    protected virtual DataSet GetDataSet(string command, string tableName, string databaseKey)
    

  • Returns a new, untyped DataSet with the specified table containing the results of the command string executed against the default database.

    protected virtual DataSet GetDataSet(string command, string tableName)
    

  • Returns a new, untyped DataSet with the default table containing the results of the command string executed against the default database.

    protected virtual DataSet GetDataSet(string command)
    

  • Returns a new, untyped DataSet with the specified table containing the results of the command string (based on command type) executed against the specified database.

    protected virtual DataSet GetDataSet(string command, string tableName, string databaseKey, CommandType cmdType)
    

  • Returns a new, untyped DataSet with the specified table containing the results of the command string (based on command type) executed against the default database.

    protected virtual DataSet GetDataSet(string command, string tableName, CommandType cmdType)
    

  • Returns a new, untyped DataSet with the default table containing the results of the command string (based on command type) executed against the default database.

    protected virtual DataSet GetDataSet(string command, CommandType cmdType)
    

  • Returns a new, untyped DataSet with the specified table containing the results of executing the Select Command object against the specified database.

    protected virtual DataSet GetDataSet(IDbCommand command, string tableName, string databaseKey)
    

  • Returns a new, untyped DataSet with the specified table containing the results of executing the Select Command object against the default database.

    protected virtual DataSet GetDataSet(IDbCommand command, string tableName)
    

  • Returns a new, untyped DataSet with the default table containing the results of executing the Select Command object against the default database.

    protected virtual DataSet GetDataSet(IDbCommand command)
    

    Example
    This method calls the business object's GetDataSet method, passing the name of the stored procedure to be executed and two parameter objects. It assumes the business object's DefaultCommandType (usually specified at the ABusinessObject level) is set to CommandType.StoredProcedure

    The GetDataSet method runs the stored procedure returning a DataSet containing the results of the stored procedure execution.

    In C#:

    public DataSet GetOrdersByCustomerAndEmployee(string custID, int employeeID)
    {
    	// Get a DataSet filled with the result set
    	return this.GetDataSet("OrdersByCustomerAndEmployee",
    		this.CreateParameter("@CustomerID", custID),
    		this.CreateParameter("@EmployeeID", employeeID));
    }

    In VB .NET:

    Public Function GetOrdersByCustomerAndEmployee(ByVal custID As StringByVal employeeID As IntegerAs DataSet
    	' Get a DataSet filled with the result set
    	Return Me.GetDataSet("OrdersByCustomerAndEmployee",
    	Me.CreateParameter("@CustomerID", custID),
    	Me.CreateParameter("@EmployeeID", employeeID))
    End Function


    Note: Both the GetDataSet and FillDataSet methods of mmBusinessObject possess overloads that accept a variable number of IDbDataParameter objects (by making use of the C# params keyword). This allows you to pass one or more parameter objects separated by commas to these methods. Alternately, rather than passing a list of parameters, you can create an IDbDataParameter array filled with parameters and pass this instead.

    FillDataSet

    Here is the description and signature of the FillDataSet overloads.

    • Fills the DataSet's specified table with the results of the command string (based on command type) w/ parameters executed against the specified database.

      protected virtual void FillDataSet(DataSet ds, string command, string tableName,
      	string databaseKey, CommandType cmdType, params IDbDataParameter[] cmdParams)

    • Fills the DataSet's specified table with the results of the command string (based on command type) w/ parameters executed against the default database.

      protected virtual void FillDataSet(DataSet ds, string command, string tableName,
      	string databaseKey, CommandType cmdType, params IDbDataParameter[] cmdParams)

    • Fills the DataSet's default table with the results of the command string (based on command type) w/ parameters executed against the default database.

      protected virtual void FillDataSet(DataSet ds, string command, CommandType cmdType,
      	params IDbDataParameter[] dataParams)

    • Fills the DataSet's specified table with the results of the command string w/ parameters executed against the specified database.

      protected virtual void FillDataSet(DataSet ds, string command, string tableName,
      	string databaseKey, params IDbDataParameter[] dataParams)

    • Fills the DataSet's specified table with the results of the command string w/ parameters executed against the default database

      protected virtual void FillDataSet(DataSet ds, string command, string tableName,
      	params IDbDataParameter[] dataParams)

    • Fills the DataSet's default table with the results of the command string w/ parameters executed against the default database

      protected virtual void FillDataSet(DataSet ds, string command,
      	params IDbDataParameter[] dataParams)

    • Fills the DataSet's specified table with the results of the command string executed against the specified database.

      protected virtual void FillDataSet(DataSet ds, string command, string tableName, string databaseKey)
      

    • Fills the DataSet's specified table with the results of the command string executed against the default database

      protected virtual void FillDataSet(DataSet ds, string command, string tableName)
      

    • Fills the DataSet's default table with the results of the command string executed against the default database

      protected virtual void FillDataSet(DataSet ds, string command)
      

    • Fills the DataSet's specified table with the results of the command string (based on command type) executed against the specified database.

      protected virtual void FillDataSet(DataSet ds, string command, string tableName, string databaseKey, CommandType cmdType)
      

    • Fills the DataSet's specified table with the results of the command string (based on command type) executed against the default database.

      protected virtual void FillDataSet(DataSet ds, string command, string tableName, CommandType cmdType)
      

    • Fills the DataSet's default table with the results of the command string (based on command type) executed against the default database.

      protected virtual void FillDataSet(DataSet ds, string command, CommandType cmdType)
      

    • Fills the default table in the DataSet by executing the Select Command object against the specified database

      protected virtual void FillDataSet(DataSet ds, IDbCommand command, string tableName, string databaseKey)
      

    • Fills the DataSet's specified table with the results of executing the Select Command object against the default database

      protected virtual void FillDataSet(DataSet ds, IDbCommand command, string tableName)
      

    • Fills the DataSet's default table with the results of executing the Select Command object against the default database

      protected virtual void FillDataSet(DataSet ds, IDbCommand command)
      

      Example
      In the following code sample, the first line of code creates an instance of a typed DataSet. The second line of code calls the business object's FillDataSet() method, passing the DataSet to be populated, the name of the stored procedure, and a parameter object

      In C#:

      public DataSet GetCustomerOrdersDetail(int orderID)
      {
      	// Instantiate your typed DataSet here
      	DataSet ds = new MyTypedDataSet();
       
      	// Get a DataSet filled with the result set
      	this.FillDataSet(ds, "CustOrdersDetail"this.CreateParameter("@OrderID", orderID));
       
      	return ds;
      }

      In VB .NET:

      Public Function GetCustomerOrdersDetail(orderID As int) As DataSet
       
      	' Instantiate your typed DataSet here
      	Dim ds As New MyTypedDataSet()
       
      	'Get a DataSet filled with the result set
      	FillDataSet(ds, "CustOrdersDetail"Me.CreateParameter("@OrderID", orderID))
       
      	Return ds
      End Function

    See also:
    Retrieving Business Entities and Business Entity Lists


© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 02/12/26
Comment or report problem with topic