Generic 'T, K' Database Component



Why did I use Generic <T, K>?

This keeps the number of overloaded methods down to a minimum without using objects. Let me explain.
Method One, without Generic <T, K>:

  1. You would be to have an overloaded method for every type of CONNECTION and DATATYPE.
  2. Because of the different DATATYPES, you would need to rename the methods.
  3. I am sure that you can see that very soon, you have tons of methods and tons of code.
  4. For a developer user of the component this becomes complex.
  5. From a maintenance/enhancement point of view, this becomes tiring and can be costly.

Method Two, without Generic <T, K>:
  1. You have the same methods that I do, but both the CONNECTION and the DATATYPE are cast as objects.
  2. Well we all know that we can have compile issues and usability issues with objects, which is where Generics <T, K> are now part of Visual Studio 2005.

Technical Details of the component
  1. I have replaced the T with CONNECTION and the K with DATATYPE.

  2. When initializing the object, the first parameter, your CONNECTION, can be any of the following types:
    1. A Connection String
    2. A System.Data.SqlClient.SqlConnection
    3. A System.Data.OleDb.OleDbConnection
    4. A System.Data.Odbc.OdbcConnection
    5. An ADODB.Connection
    6. A Oracle.DataAccess.Client.OracleConnection
    7. To name a few...

  3. When Initializing the object, the second parameter, your DATATYPE, can be any of the following types:
    1. A System.String, here your data would be a disconnection XML formatted string, needed by those systems that can only handle strings.
    2. A System.Data.DataSet
    3. A System.Data.DataTable
    4. A System.Xml.XmlDocument

  4. There are four (4) exposed Public Methods, three (3) of them are overloaded:
    1. public DATATYPE Create(CONNECTION, string sql, string tableName)
    2. public DATATYPE Create(string provider, string sql)
    3. public DATATYPE Create(CONNECTION, string sql, string[] parameterList, string tableName, int Timeout)
    4. public void Update(CONNECTION, DATATYPE, string sql, string tableName)

gdc1.gif
Usage here is when you want to update/insert/etc data utilizing Typed DataSets

gdc2.gif 
When the user updates the appropriate line/column
gdc3.gif
 
After editing the data, the next method called (as highlighted below), will update the table utilizing Typed Dataset. This also works for inserts as well.
gdc4.gif

Up Next
    Ebook Download
    View all
    Learn
    View all