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()
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()