472,805 Members | 949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

Questions on application design

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
Nov 20 '05 #1
2 1777
Cor
Hi Matthew,

This kind of sollutions cannot be handled in detail I think, but when you
ask am I on the right track, I think yes. One of the things that triggered
me direct was that I would look for what the windows integrated security for
users and passwords could do for me.

Another thing was where to hold the user information, for your application,
have a look for that what an XMLdataset as file can do for you or the
registry.

I do not believe that a record class will help you, I think it will give you
only more work.

A dataset is a class that holds rows (records), which come from the datarow
class.

When you are used to it, it is much easier to use than the recordset.

I believe that by building those records classes you are loosing the very
usefull posibilities by instance from dataview, the datarowcollection class
and from the datatableclass.

I hope this helps a little bit?

Cor
Nov 20 '05 #2
Matthew,
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.) The easiest way is to use the OLE DB client in System.Data.OleDb namespace,
as all those databases support an OLE DB provider. Another option would be
the ODBC client in System.Data.Odbc. Both OLE DB & ODBC are designed to work
with "any" database in a general manner. However each database may still
have unique SQL syntax "features".

However to get better performance from Oracle, SQL Server, and MySql you
should use their respective client in their own namespaces (for example
System.Data.SqlClient for SQL Server). Using the database specific client
complicates things, but not too much. Read on...
I have created a Database module structured like so: Rather then create a Database Module, you may want to consider a Database
Class that has overrideable methods. Each database client (Access, SQL
Server, Oracle) would be a concrete class. As then you can use the Database
Class polymorphically.

The Database Class itself could have a shared method (A Factory Method) that
returns the current instance of the configured Database method. I would
consider implementing this by reading the type itself from the config file.

Something like:

Public MustInherit Class DataBase

Private Shared m_current As DataBase

Shared Sub New()
' Dynamically load an assembly, and create an object
Dim type As Type
type =
Type.GetType(ConfigurationSettings.AppSettings("da tabase")
' appsettings/database = "mynamespace.myclass, myassembly"
m_current = DirectCast(Activator.CreateInstance(type), Database)
End Sub

Public Shared Readonly Property Current() As DataBase
Get
Return m_current
End Get
End Property

Public Property DBUsername
Public MustOverride Function ReturnDataset(ByVal SQLString) as
Data.Dataset
Public MustOverride UpdateDatabase(ByVal SQLString) as Boolean
End Class
' Uses the OleDb client
Public Class OleDbDatabase
Inherits Database
Public Overrides Function ReturnDataset(ByVal SQLString) as
Data.Dataset
Public Overrides UpdateDatabase(ByVal SQLString) as Boolean
End Class

' Uses the SqlClient
Public Class SqlServerDatabase : Inherits Database

' Uses the OracleClient
Public Class OracleDatabase : Inherits Database

' Uses the MySqlClient
Public Class MySqlDatabase : Inherits Database

By creating new classes that inhert from Database, each possible in their
own DLL, you can add new database clients without requiring your app to be
recompiled. Note database client specific types (SqlCommand for example)
would not be exposed from the above classes.

NOTE: Rather then having "database" in the appSettings section of
app.config, I would consider creating a new section, that included both the
database, connection string, and other "database" specific settings that are
needed.
Function ReturnDataset(ByVal SQLString) as Data.Dataset (Return
Rather then returning a DataSet consider have the DataSet as a parameter, as
then you could put multiple DataTable, that are inter-related into a single
DataSet.
Function ReturnDataset(ByVal SQLString) as Data.Dataset
Sub UpdateDatabase(ByVal SQLString) as Boolean Rather then accepting SQL strings (that may vary depending on your access
method, I would consider implementing a DataGateway[3] for each table, then
use the Database Class as an Abstract Factory Pattern[4] to get the correct
Gateway for the correct access method.

Also if you are using DataSets, you need 3 parameterized commands to update
the database, an UpdateCommand, a DeleteCommand, and an InsertCommand, see
the four commands on DataAdapter[1].
For each table I have created a "Record" class module structured
like so: You could use a Domain Model[2] as you are describing or a Typed Dataset[1],
IMHO it really depends on how much "business" logic you want in your
objects. I've used Domain Models, Typed Datasets, and untyped Datasets,
depending on the requirements of the project.

Some useful references:

[1] David Sceppa's book "Microsoft ADO.NET - Core Reference" from MS press
is
both a good tutorial on ADO.NET & a good desk reference for later. It covers
data access and DataSets.

[2] Rockford Lhotka's book "Expert One-On-One Visual Basic .NET Business
Objects" from A! Press, provides a framework for data binding to your own
domain (business) objects.
http://www.lhotka.net

[3] Martin Fowler's book "Patterns of Enterprise Application Architecture"
from Addison Wesley press covers both DataSets & Domain models at a higher
level plus a couple of other possibilities for managing your data. The
previous two books go into detail on two of the Martin's patterns...

[4] GOF's book "Design Patterns - Elements of Reusable Object-Oriented
Software" from Addison Wesley, covers a number of useful design patterns for
creating OO programs. GOF = Erich Gamma, Richard Helm, Ralph Johnson, and
John Vlissides. James W. Cooper's book "Visual Basic Design Patterns - VB6.0
and VB.NET" is a good companion book for the GOF book, as James explains the
patterns themselves in both VB6 & VB.NET syntax.

Hope this helps
Jay

"Matthew Hood" <No****@NoSpam.com> wrote in message
news:uc**************@TK2MSFTNGP11.phx.gbl... 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

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Olav.NET | last post by:
I am a .NET/C++ developer who is supposed to do some work with Access. I do not know much about it except for the DB part. Questions: *1* I am looking for INTENSIVE books to get quickly up to...
8
by: NH | last post by:
Hi, I'm looking for some opinions and advice on designing ASP.Net apps. Let me explain my approach to how I currently design and hopefully you can give me some advice. I create systems for a...
6
by: google | last post by:
I have a few general questions. I am working on a new database to be used within my company. I would like to give a couple of people, particularly HR, the ability to add and delete Access users,...
13
by: M.Siler | last post by:
Let me clarify from my last post. I am not using these 4 questions as the sole screening method. Currently in, the Tampa Bay area (Florida) there is an extreme shortage of C# developers. We have...
3
by: Sukh | last post by:
I have to design a "Online Test Application" and application is going to display question and answers.All the questons are objective type so there is four answer for each question. My Question is...
4
by: Steve | last post by:
I have read a couple articles online, read my Jesse Liberty book but I am still confused as to just what the best practices are for using exceptions. I keep changing how I'm working with them and...
14
by: shamirza | last post by:
Question Do ActiveX DLLs made in VB still need the VB runtimes on the machine? ________________________________________ Answer In a word, Yes. Visual Basic does not support what is known...
1
by: dreamznatcher | last post by:
Hello, Not sure whether this is the right group to ask this, but there are so many groups out there I got kinda lost! Please help me out on this career dilemma I'm going through, or kindly forward...
11
by: The Natural Philosopher | last post by:
1/. Can anyone tell me why renaming a function from 'update()' to 'form_update()' makes Safari work when it didn't before? 2/. I would LIKE if possible, to do the following. User is filling...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.