M
Matthew Hood
My company has expressed a desire to convert an existing MS Access
application to a full VB.NET application. My experience is with VB6 so I
want to ask a few questions and get some input on the best way to handle the
following design:
Situation: We want to allow our customers to install with one of the
following options:
1. Use an Access MDB file as the data backend.
2. Use a SQL Server backend. (Either MS SQL, or MySQL)
3. Use an Oracle backend. (This option would be implemented at a later
date.)
Question: What would be the best way handle all data access within all the
forms?
My initial solution: (Don't know if it's the best way)
I have created a Database module structured like so:
**
Property DBType (Specifies the type of backend to use)
Property DBServer (Specifies the SQL Server)
Property DBUsername (Specifies the SQL Server account to use)
Property DBPassword (Specifies the SQL Server account's
password.)
Function ReturnDataset(ByVal SQLString) as Data.Dataset (Return
a dataset object with the specified SELECT command.)
Sub UpdateDatabase(ByVal SQLString) as Boolean (Update the
database using the specified UPDATE/INSERT command)
**
For each table I have created a "Record" class module structured
like so:
**
Property Field1
Property Field2
Property Field3, etc.
Property Dataset as Data.Dataset (Allow me to bind
controls/grids when needed)
Sub OpenData() (Opens a dataset and populates the properties)
Sub UpdateData() (Updates the database with new/changed data)
**
For the data forms I open the form, create a new "Record" class
module, and if appropriate, execute the OpenData routine.
Then I set the control values to the approprate property (through
code).
When appropriate, I then save any changes/updates using the UpdateDa
ta routine.
The idea I had by using the above methodology, is
1. It allows me to specify in 1 place the type of database to use in
the Database module.
2. The record class modules aren't aware of what backend they are
using. They all use the same routines to update and return data. (Using
T-SQL syntax hardcoded into the class module)
Am I on the right track with this type of design? Or is there an easier and
better way of accomplishing this.
Thanks for any info/feedback.
-Matt
application to a full VB.NET application. My experience is with VB6 so I
want to ask a few questions and get some input on the best way to handle the
following design:
Situation: We want to allow our customers to install with one of the
following options:
1. Use an Access MDB file as the data backend.
2. Use a SQL Server backend. (Either MS SQL, or MySQL)
3. Use an Oracle backend. (This option would be implemented at a later
date.)
Question: What would be the best way handle all data access within all the
forms?
My initial solution: (Don't know if it's the best way)
I have created a Database module structured like so:
**
Property DBType (Specifies the type of backend to use)
Property DBServer (Specifies the SQL Server)
Property DBUsername (Specifies the SQL Server account to use)
Property DBPassword (Specifies the SQL Server account's
password.)
Function ReturnDataset(ByVal SQLString) as Data.Dataset (Return
a dataset object with the specified SELECT command.)
Sub UpdateDatabase(ByVal SQLString) as Boolean (Update the
database using the specified UPDATE/INSERT command)
**
For each table I have created a "Record" class module structured
like so:
**
Property Field1
Property Field2
Property Field3, etc.
Property Dataset as Data.Dataset (Allow me to bind
controls/grids when needed)
Sub OpenData() (Opens a dataset and populates the properties)
Sub UpdateData() (Updates the database with new/changed data)
**
For the data forms I open the form, create a new "Record" class
module, and if appropriate, execute the OpenData routine.
Then I set the control values to the approprate property (through
code).
When appropriate, I then save any changes/updates using the UpdateDa
ta routine.
The idea I had by using the above methodology, is
1. It allows me to specify in 1 place the type of database to use in
the Database module.
2. The record class modules aren't aware of what backend they are
using. They all use the same routines to update and return data. (Using
T-SQL syntax hardcoded into the class module)
Am I on the right track with this type of design? Or is there an easier and
better way of accomplishing this.
Thanks for any info/feedback.
-Matt