Question method to variable change connection between oledb and sql

mibock

New member
Joined
Feb 6, 2011
Messages
4
Programming Experience
10+
I want to give my windowsapplication a param to say how the programm connects, uses datareaders, command-objects etc. by OleDB or by SQL (the database may be Access or MS-SQL-Server). The syntax I use for this objects seems to be the same, but the objects itselve are different.

Dim oCON As OleDbConnection
Dim oCMD As OleDbCommand
Dim oCMD1 As OleDbCommand
Dim oDR As OleDbDataReader
Dim oDR1 As OleDbDataReader

Dim oCON_sql As SqlConnection As SqlConnection
Dim oCMD_sql As SqlCommand
Dim oCMD1_sql As SqlCommand
Dim oDR_sql As SqlDataReader
Dim oDR1_sql As SqlDataReader

Later I have to write double code to either use the OleDB-object or the SQL-object:

strSignal = oDR("Signal").toString

or

strSignal = oDR_sql("Signal").toString

But I do not want to double all the code where I use this objects because all fields I get from these objects are the same.

I think there must be a way / trick to do it. If you have a code-example I would be very lucky.

Sorry for my rusty English.

Yours, Michael
 
Follow the Blog link in my signature and check out my post on creating a database-independent data access layer.

The other alternative would be to just use OleDb in all cases, and change the connection string appropriately. There's an OLE DB provider for SQL Server so that will work, although you will lose some features and performance when connecting to SQL Server using OleDb compared to using SqlClient.
 
Back
Top