Class to handle DB connections

Discussion in 'ASP .Net' started by Simon Harris, Nov 2, 2004.

  1. Simon Harris

    Simon Harris Guest

    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()
    Simon Harris, Nov 2, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dietrich
    Replies:
    1
    Views:
    637
    Joe Smith
    Jul 22, 2004
  2. Leon
    Replies:
    2
    Views:
    521
  3. =?ISO-8859-1?Q?KLEIN_St=E9phane?=
    Replies:
    3
    Views:
    444
    hanumizzle
    Oct 6, 2006
  4. jobs
    Replies:
    2
    Views:
    886
  5. spammtrapp

    Best way to handle sql-connections in webservices?

    spammtrapp, Oct 21, 2009, in forum: ASP .Net Web Services
    Replies:
    2
    Views:
    904
    CSharpner
    Nov 11, 2009
Loading...

Share This Page