Generic 'T, K' Database Component
.NET, ADO.NET, ADODB.Connection, C#, DataSets, DATATYPE, Generic Database Component., System.Data.DataSet, System.Data.DataTable, System.Xml.XmlDocument, Visual Studio 2005,
I have written a C# 2.0 (Visual Studio 2005), Generic Database component, The component has simplified the architecture and the implementation by allowing me to keep the number of overloaded methods to a minimum.
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>:
- You would be to have an overloaded method for every type of CONNECTION and DATATYPE.
- Because of the different DATATYPES, you would need to rename the methods.
- I am sure that you can see that very soon, you have tons of methods and tons of code.
- For a developer user of the component this becomes complex.
- From a maintenance/enhancement point of view, this becomes tiring and can be costly.
Method Two, without Generic <T, K>:
- You have the same methods that I do, but both the CONNECTION and the DATATYPE are cast as objects.
- 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
- I have replaced the T with CONNECTION and the K with DATATYPE.
- When initializing the object, the first parameter, your CONNECTION, can be any of the following types:
- A Connection String
- A System.Data.SqlClient.SqlConnection
- A System.Data.OleDb.OleDbConnection
- A System.Data.Odbc.OdbcConnection
- An ADODB.Connection
- A Oracle.DataAccess.Client.OracleConnection
- To name a few...
- When Initializing the object, the second parameter, your DATATYPE, can be any of the following types:
- A System.String, here your data would be a disconnection XML formatted string, needed by those systems that can only handle strings.
- A System.Data.DataSet
- A System.Data.DataTable
- A System.Xml.XmlDocument
- There are four (4) exposed Public Methods, three (3) of them are overloaded:
- public DATATYPE Create(CONNECTION, string sql, string tableName)
- public DATATYPE Create(string provider, string sql)
- public DATATYPE Create(CONNECTION, string sql, string parameterList, string tableName, int Timeout)
- public void Update(CONNECTION, DATATYPE, string sql, string tableName)
Usage here is when you want to update/insert/etc data utilizing Typed DataSets
When the user updates the appropriate line/column
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.