Access and SQL (also Excel) Database Handler for Newbies and the LazyI've rushed the earlier part of this tutorial so I've decided to slow down and explain things a little.
Access and SQL (also Excel) Database Handler for Newbies and the Lazy is what I use in my databse applications
because of the following reasons:
-I'm lazy
-I dont line importing stuff for every small database operation
-I don't want to remember connection strings
It has worked so far for me that's why I've been extending it to other areas: It started with MS SQL and MS Access
2003, 2007 and now can manage Excel 2003 and 2007. I have an upcoming project to do with mySQL and hopefully, I'll
extended this handler to cover that. I also intended to add features such as Record Locking and Database
Transactions.
Enough of the small talk, how is this better than doing stuff straight?
To connect to a database, you have to
1. first of all declare a connector/connection
2. define a connection string to connect to a database
3. declare a command to use in queries and
4. declare a datareader/dataset to get information in and out of the database.
These steps are simplified in DB Handler.
(before you read on, you might want to download a copy attached below this writeup so that you can go along)
ConnectionDeclaring a connection is based o what database you want to access. You can use the OleDb, ADODB, SQL or other
connections. As a newbie, this might be confusing to you because all you know is you have a database which you
want to write to and read from, you don't give a damn about connections, just show me how to display data from my
database. Now, I'll try to explain things in three levels: Newbie, Intermediate and Advanced. Therefore, the first
step in database I/O with this handler is to define your database:
Newbie:
CODE
Dim MyDataBase as New DB
MyDataBase.Type = DBType.ACCESS 'or DBType.SQL or DBType.EXCEL
Intermediate:
CODE
Dim MyDataBase as New DB(DBType.ACCESS)
Advanced:
CODE
Dim MyDataBase as New DB(DBType.ACCESS, "Provider=Microsoft.ACE.OLEDB.12.0; bla bla bla")
That is it. For us newbies (yes, I am one), I declare my database first of all and then set the kind of database
I'm using (either MS Access, MS SQL Server or MS Excel). For the intermediate, they'll like to do things just a
little bit above newbies: declare the database and assign it's type immediately. For the tough guys, they're
always a step ahead and doing things the hard way, they have declared the database, specified its type and defined
its connection string (that's why not everyone is a toughie).
Connection StringFor the newbies and intermediates, you'll have to define some of your database properties so that the DB Handler
can build (or guess) a connection string for the connection. Advanced users can just use the
ConnectionString
property to just set it. The following properties should be defined:
Note: Y-Yes, N-No, O-Optional
CODE
Property MS-SQL MS-Access MS-Excel
-Type Y Y Y 'already specified above
-Provider O O O
-DataSource Y use Path use Path
-Path clear Name 1st Y Y
-Name Y use Path use Path
-UseWindowsID Y Invalid Invalid
-Username set WinId false Y Ignored
-Password set WinId false Y Ignored
That's it, you don't have to mind some of them because, to connect to the access database on my desktop, i just
use this
CODE
Dim MyDataBase As New DB
MyDataBase.Type = DBType.ACCESS 'i told you im a newbie
MyDataBase.Path = "C:\Users\olibenu\Desktop\pagoda.accdb"
This post has been edited by olibenu: 20 Oct, 2009 - 04:05 AM