Visit
SearchWinDevelopment.com,
the Visual Basic-Specific Search Engine.
FREE benefits include Daily News, Developer Tips, Career Center, VB
Forums & more.
Author: Muhammad Musa Ali Date Submitted: 11/15/2001 Category: Database Compatibility: VB 6
This code has been accessed 35129 times.
Task: Database Access Class for VB and ADO 2.5/2.6
I am presenting a very simple class to use for database access using VB 6.0 and ADO for SQL Server 7.0/2000. By changing the Connection string, this can be used for any database. Each VB developer needs this sort of thing while doing database related work.Add this class to your project and name it say ‘Cdatabse’.
Provide the Server name, Database name, user name and password as
StrServer= “ MyServer”
StrDB = “MyDatabaseName”
StrUserName = “ TestUser”
StrPassword = “ MyPassword
Now, wherever you need to do database access, just instantiate this class as
Dim Cdata as new Cdatabse
The initialize event of the class will take the server name, database name, user name and password.
Dim rst as ADODB.Recordset ‘ recordset to be used
Call Cdata.connect ‘
In order to get a dynamic recordset, build your query and pass it to the GetRecordset function as
Say strQuery = “ Select * from table1”
Cdata. GetRecordset strQuery, rst
Now you can use this recordset as you want.
In order to get a forward only recordset, use the GetInfo method as
Cdata. GetInfo strQuery, rst
For updation or deletions, use Update method by passing your query as
Cdata.Update strQuery
And use the Disconnect method in the end.