Hello!
I am new to VisualBasic, but I need to do some work on a VB project. Currently I am struggling with this problem:
A Module connects to a local Access database. The connection is a ADODB.Connection(). The connection seems to work
At least Connect is set to "True";
My Problems:
1. I would like to add the following check to some parts of the code:
... Visual Basic 2008 Express Edition tells me, "adStateOpen" is not declared. I tried to find a reference for the Class ADODB, to get the correct properties and methods for the object the Connection() method return, but I could not find such a reference for this class.
2. I am not sure about the usage of the conn.Open and conn.Close methods. I have a function, that is called many times as it reads out many single parameters from the database. Should I open and close the connection within this method, or should I leave the connection open while doing multiple calls to the database.
I hope to get some help on this.
Kind regards,
Andy
I am new to VisualBasic, but I need to do some work on a VB project. Currently I am struggling with this problem:
A Module connects to a local Access database. The connection is a ADODB.Connection(). The connection seems to work
Code:
Public conn As New ADODB.Connection()
Function Connect() As Boolean
On Error GoTo Connect_Err
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & My.Application.Info.DirectoryPath & "\database.mdb;Jet OLEDB:Database Password=myOtherPassword"
conn.Open()
Connect = True
conn.Close()
Exit Function
Connect_Err:
Connect = False
End Function
My Problems:
1. I would like to add the following check to some parts of the code:
Code:
If (conn.State = adStateOpen) Then
2. I am not sure about the usage of the conn.Open and conn.Close methods. I have a function, that is called many times as it reads out many single parameters from the database. Should I open and close the connection within this method, or should I leave the connection open while doing multiple calls to the database.
Code:
Function GetDbParam(ByRef variable As Object) As String
Dim r As Object
conn.Open()
r = conn.Execute("select * from params where variable = '" & CStr(variable) & "'")
If Not r.EOF Then
If IsDBNull(r("value")) Then
conn.Close()
Exit Function
End If
GetDbParam = r("value").ToString()
End If
conn.Close()
End Function
Kind regards,
Andy