Article Options
Premium Sponsor
Premium Sponsor

 »  Home  »  Data Programming  »  Business Mate: Using the Generic Database Class
 »  Home  »  Data Programming  »  ADO.NET  »  Business Mate: Using the Generic Database Class
 »  Home  »  Data Programming  »  Microsoft Access  »  Business Mate: Using the Generic Database Class
Business Mate: Using the Generic Database Class
by Charles Profitt | Published  02/10/2005 | Data Programming ADO.NET Microsoft Access | Rating:
Charles Profitt
Charles Profitt currently works as both a developer and system administrator for a K-12 school district. His diverse experience includes working with Netware, Active Directory, SQL Server (2000 and 2005), IIS 6, Lotus Notes and Visual Studio.Net (2002, 2003, and 2005). His language of choice is C#. Charles has created several windows and web bases applications in since November of 2002. 

View all articles by Charles Profitt...
Creating a dataSet and a DataView
We have to use the class we created. At the top of your code, above the namespace section, you have to add the following using statements:

using System.Data;
using System.Data.OleDb;

If you want to not have to write out the complete namespace of your class you will need to include that:

using System.Data;
using System.Data.OleDb;
using Business_Mate.classes;

The remainder of the example code will assume you used the first example and didn't type "using Business_Mate.classes;" I normally add an additional static void for each DataSet I want to retrieve more than once. The first thing I want to retrieve is a list of users with their associated addresses.

public static DataSet dsContactFullName()

string select =
     "SELECT contactID, fullName, street, city, state, zipcode FROM contactFullName";
DataSet dsContact = classes.database.ds(select, "contactFullName");
return dsContact;


This makes use of the generic DataSet code in the previous part of this series by passing a select string and table name. Now that I showed you that I make another function to return a specific DataSet I also prefer to "close" the generic function and make it private as detailed below:

private static DataSet ds(string select, string table)

OleDbConnection objConnection = GetConnection();
OleDbCommand objCommand = new OleDbCommand(select, objConnection);
OleDbDataAdapter da = new OleDbDataAdapter(objCommand);
DataSet ds = new DataSet();

da.Fill(ds, table);

catch (OleDbException e)


return ds;


The difference is the keyword "private" instead of "public". This makes the function unavailable outside the class. Now if I wanted to to sort the data or filter it I would create a DataView.

public static DataView dvContactFullName(string filter)

DataSet ds = new DataSet();
ds = dsContactFullName();
DataView dv = new DataView(ds.Tables["contactFullName"]);
dv.RowFilter = filter;
return dv;


So you should now know how to take the generic dataset class and make a specific dataset and also a dataview. In the next part of this series I will cover using a dataset to fill a listbox.

Until then keep coding.

How would you rate the quality of this article?
1 2 3 4 5
Poor Excellent
Tell us why you rated this way (optional):

Article Rating
The average rating is: No-one else has rated this article yet.

Article rating:3 out of 5
 38 people have rated this page
Article Score26713
Sponsored Links