|
-
more ADO stuff
I have been experimenting a little further with ADO and the use of DLL class
files for connectivity to an Access database table etc . Now I can not seem
to work out how to utilise the connection's recordset (two fields for two
text boxes) and display it in the two text boxes in the main project. I am
specifically trying to keep the database functions in the class file (referenced
from the main project files) and the display (GUI) stuff) in the main project................Can
someone please help ?
=============
project file
=============
Option Explicit
Private dbConnectionClass As DBConnectionProject.dbConnectionClass
Private Sub OpenConnectionCommand_Click()
Dim strConnect As String
Dim strProvider As String
Dim strDataSource As String
Dim strDatabaseName As String
Dim strLogon As String
strProvider = "Provider=Microsoft.Jet.OLEDB.3.51;"
strDataSource = App.Path
strDatabaseName = "\northwind.mdb;"
strDataSource = "Data Source=" & strDataSource & strDatabaseName
strConnect = strProvider & strDataSource
Set dbConnectionClass = New DBConnectionProject.dbConnectionClass
dbConnectionClass.DataBaseConnectionInformation = strConnect
dbConnectionClass.OpenDatabaseConnection
ConnectionLabel.Caption = strConnect
ShowButtons (2)
dbConnectionClass.OpenRecords ("select * from employees")
End Sub
Private Sub CloseConnectionCommand_Click()
dbConnectionClass.CloseRecords
dbConnectionClass.CloseDatabaseConnection
ShowButtons (1)
End Sub
Private Sub ShowButtons(number As Integer)
Select Case (number)
Case 1: OpenConnectionCommand.Enabled = True
CloseConnectionCommand.Enabled = False
Case 2: OpenConnectionCommand.Enabled = False
CloseConnectionCommand.Enabled = True
End Select
End Sub
Private Sub FirstCommand_Click()
dbConnectionClass.FirstRecord
LoadControls
End Sub
Private Sub PreviousCommand_Click()
dbConnectionClass.PreviousRecord
LoadControls
End Sub
Private Sub NextCommand_Click()
dbConnectionClass.NextRecord
LoadControls
End Sub
Private Sub LastCommand_Click()
dbConnectionClass.LastRecord
LoadControls
End Sub
Private Sub LoadControls()
End Sub
Private Sub ClearControls()
FirstNameText.Text = ""
SecondNameText.Text = ""
End Sub
=============
DLL class file
=============
Option Explicit
Public mdbConnection As ADODB.Connection
Public mdbRecords As ADODB.Recordset
Private mstrDataBaseConnectionInformation As String
Public Property Let DataBaseConnectionInformation(ByVal vData As String)
mstrDataBaseConnectionInformation = vData
End Property
Public Property Get DataBaseConnectionInformation() As String
DataBaseConnectionInformation = mstrDataBaseConnectionInformation
End Property
Public Sub OpenDatabaseConnection()
Set mdbConnection = New ADODB.Connection
mdbConnection.ConnectionString = mstrDataBaseConnectionInformation
mdbConnection.Open
End Sub
Public Sub OpenRecords(SQL As String)
Set mdbRecords = New ADODB.Recordset
mdbRecords.ActiveConnection = mdbConnection
mdbRecords.Open SQL, mdbConnection, adOpenDynamic
End Sub
Public Sub FirstRecord()
If mdbRecords.BOF = False Then mdbRecords.MoveFirst
End Sub
Public Sub PreviousRecord()
If mdbRecords.BOF = False Then mdbRecords.MovePrevious
If mdbRecords.BOF = True Then mdbRecords.MoveFirst
End Sub
Public Sub NextRecord()
If mdbRecords.BOF = False Then mdbRecords.MoveNext
If mdbRecords.BOF = True Then mdbRecords.MoveLast
End Sub
Public Sub LastRecord()
If mdbRecords.BOF = False Then mdbRecords.MoveLast
End Sub
Public Sub CloseRecords()
mdbRecords.Close
Set mdbRecords = Nothing
End Sub
Public Sub CloseDatabaseConnection()
mdbConnection.Close
Set mdbConnection = Nothing
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks