Class to handle DB connections

S

Simon Harris

Hi All,

I'm trying to create a class to connect/disconnect a database. Code I have
so far is below, problem is that the closeconn function gives me an error -
Name 'SPDOleDbConnection' is not declared.

Also getting the same problem in my code where I want to use the connection
(also shown below)

Would appreciate it if anyone has any ideas - Surely I dont have to repeat
this code everytime I open/close a connection! :)

Regards,
Simon.


Code to open/close connection
========================
Public Class DataBase

Public Function OpenConn() As System.Data.OleDb.OleDbConnection
Dim configurationAppSettings As
System.Configuration.AppSettingsReader = New
System.Configuration.AppSettingsReader
Dim SPDOleDbConnection As New OleDb.OleDbConnection
SPDOleDbConnection.ConnectionString =
CType(configurationAppSettings.GetValue("OleDbConnection1.ConnectionString",
GetType(System.String)), String)
SPDOleDbConnection.Open()
End Function
Public Function CloseConn() As System.Data.OleDb.OleDbConnection
SPDOleDbConnection.Close()
End Function

End Class

Code where I want to use the connection
===============================
Dim myCommand As New System.Data.OleDb.OleDbCommand("SELECT Country FROM
Countries WHERE CountryID = " & CountryID, SPDOleDbConnection)
Dim myReader As System.Data.OleDb.OleDbDataReader =
myCommand.ExecuteReader(CommandBehavior.CloseConnection)
While myReader.Read()
Return myReader.GetString(0)
End While
myReader.Close()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top