Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Custom data access class - IDataAdapter.SelectCommand
Message
From
11/10/2004 00:12:26
 
 
To
All
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Title:
Custom data access class - IDataAdapter.SelectCommand
Miscellaneous
Thread ID:
00950319
Message ID:
00950319
Views:
119
I am working to create a custom data access class, following the "Creating Custom Data Access Classes" topic in the MM.NET Developer's Guide, and there is one thing that is not making sense to me.

Where I'm struggling is, I don't see how to use, from within my MM.NET business object, the four SqlCommand objects that are defined in my new data access class's IDataAdapter (i.e., SelectCommand, InsertCommand, DeleteCommand, UpdateCommand).

Please consider this code from my Vendor business object:
public DataSet GetVendors()
{
	VendorDataSet ds = new VendorDataSet();
	mmDataAccessBase dao = this.GetDataAccessObject();
	IDataAdapter da = dao.CreateDataAdapter();
	da.Fill(ds);
	return ds;
}
I get the distinct feeling that I am supposed be using the "this.FillDataSet(ds,...)" method instead of the "da.Fill(ds)" method.

However, I'm confused becase the FillDataSet method doesn't have any constructors that simply take one DataSet parameter. All of the FillDataSet overloads also require either an IDbCommand or a SQL string command. Since IDataAdapter already already has all the SqlCommand objects it needs for basic operations, it seems redundant to pass it a new SqlCommand object.

I could do this, for example:
public DataSet GetVendors()
{
	VendorDataSet ds = new VendorDataSet();
	mmDataAccessBase dao = this.GetDataAccessObject();
	this.FillDataSet(ds,GetVendorSelectCommand());
	return ds;
}

private IDbCommand GetVendorSelectCommand()
{
	IDbCommand cmd = new System.Data.SqlClient.SqlCommand();
	cmd.CommandText = "SELECT * FROM Vendor";
	cmd.CommandType = System.Data.CommandType.Text;
	return cmd;
}
but I don't see the point in making a new SqlCommand that is redudant with IDataAdapter.SelectCommand. (Also, this approach is not data-source agnostic, since it uses System.Data.SqlClient.SqlCommand, because System.Data.IDbCommand is abstract and cannot be instantiated here.)

Or I could have my custom data access class expose its IDataAdapter.SelectCommand, via a method or accessor, and then do this from my business object:
public DataSet GetVendors()
{
	VendorDataSet ds = new VendorDataSet();
	mmDataAccessBase dao = this.GetDataAccessObject();
	this.FillDataSet(ds,dao.GetSelectCommand());
	return ds;
}
But this seems convoluted as well, since my business object is already has visibility to my data access object (VendorDataAccessSql), and the SqlDataAdapter within my data access object already knows how to fill a DataSet (via the IDataAdapter.Fill(ds) method). So it seems like I'm going to a lot of trouble just to tell my custom data access class something it already knows (how to fill a DataSet).

Any guidance would be appreciated here. I'm trying to do things in the "MM.NET way," and I imagine there is a correct way to resolve this problem.

Thanks,
Ric
Next
Reply
Map
View

Click here to load this message in the networking platform