I have the following code (forgive the lack of try...finally statements as I am new to .net) that throws the ConnectionString property not initialized error.
Public Function CustomerExists(ByVal pstrSQL As String) As Boolean
On Error GoTo CustomerExists_err
'returns a true value if a customer exists
Me.OleDbConnection1.Open()
Dim myCommand As New OleDb.OleDbCommand
myCommand.Connection = Me.OleDbConnection1
myCommand.CommandText = "SELECT COUNT(*) AS Expr1 FROM(tblCustomer)" & pstrSQL
Dim rstCount As Int32
rstCount = myCommand.ExecuteScalar()
Me.OleDbConnection1.Close()
'get the value from the query
If rstCount <> 0 Then
CustomerExists = True
End If
'clean up the objects
Me.OleDbConnection1.Close()
rstCount = Nothing
CustomerExists_err:
Select Case Err.Number
Case 0
'Do nothing as this is correct
Case 3021
CustomerExists = False
'clean up the objects
Me.OleDbConnection1.Close()
rstCount = Nothing
Case Else
MsgBox(Err.Number & " - " & Err.Description)
End Select
End Function
The pstrSQL string is a where statement passed ito the function.
Can anybody help on where I am going wrong?
Thanks in advance
Jonathan
Public Function CustomerExists(ByVal pstrSQL As String) As Boolean
On Error GoTo CustomerExists_err
'returns a true value if a customer exists
Me.OleDbConnection1.Open()
Dim myCommand As New OleDb.OleDbCommand
myCommand.Connection = Me.OleDbConnection1
myCommand.CommandText = "SELECT COUNT(*) AS Expr1 FROM(tblCustomer)" & pstrSQL
Dim rstCount As Int32
rstCount = myCommand.ExecuteScalar()
Me.OleDbConnection1.Close()
'get the value from the query
If rstCount <> 0 Then
CustomerExists = True
End If
'clean up the objects
Me.OleDbConnection1.Close()
rstCount = Nothing
CustomerExists_err:
Select Case Err.Number
Case 0
'Do nothing as this is correct
Case 3021
CustomerExists = False
'clean up the objects
Me.OleDbConnection1.Close()
rstCount = Nothing
Case Else
MsgBox(Err.Number & " - " & Err.Description)
End Select
End Function
The pstrSQL string is a where statement passed ito the function.
Can anybody help on where I am going wrong?
Thanks in advance
Jonathan