Writing a class for database access

thomas008

Well-known member
Joined
Feb 17, 2009
Messages
54
Location
Belgium
Programming Experience
Beginner
Hi

I have an application ready in which I have a lot of code to access a database.
The code works well enough but now i want to write a class that completely handles my database access. So that if i should change from ACCESS to MYSQL
that i do not have to alter my code in any way. I would just have to change my class of write a new one.
I'm not sure of where to begin or what to do. Could anyone give me some startertips. I do know what classes are and how to use them. I'm just not sure of what to place in a database class.

Thanks in advance
 
I'm just not sure of what to place in a database class.

I've built my own class for doing the same thing, and I have overloaded functions for returning single values, data tables, data rows, images, executing non queries etc etc

It's all about personal preference. My preference is to build my parameterized SQL queries within my main program, and pass the query and parameters to the class to return the answer. That means that there are no fixed queries in my class - it just deals with 'execution'.
 
I've built my own class for doing the same thing, and I have overloaded functions for returning single values, data tables, data rows, images, executing non queries etc etc

It's all about personal preference. My preference is to build my parameterized SQL queries within my main program, and pass the query and parameters to the class to return the answer. That means that there are no fixed queries in my class - it just deals with 'execution'.

That is just what i want to create. I think i would be best for me to have no fixed queries in my class. Maybe with an exception of returning all tables in your database because i think the command for this depends on what type of database you are using. Not realy sure though
 
Check the Enterprise Library from Microsoft (free as in free beer). The "Data Application Blocks" offer an abstraction layer already and also take care of much of the problems resulting from different syntax in the various sql languages.
 

Latest posts

Back
Top