locked
Using a class for my database connection RRS feed

  • Question

  • I know I'm missing something really simple here, but I'm trying to create a class that I can use to access the database in my program as this is obviously used a lot throught out the program and on different forms.  I've used classes for other purposes and never had a problem but for what ever reason I can't seem to get this one to work.

    This is what I have in the class, which is basically what you would expect to see:

    Imports System.Data.SqlClient
    
    Public Class Connection
    
      Public cnn As SqlConnection
    
      Private Sub OpenConnection()
    
        cnn = New SqlConnection(My.Settings.sqlCon)
        Try
          cnn.Open()
          'For Testing
          'MessageBox.Show("Connection Open ! ", "Connection Update", MessageBoxButtons.OK, MessageBoxIcon.Information)
    
        Catch ex As Exception
          MessageBox.Show("Can not open connection ! ", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    
      End Sub
    
    
    End Class
    
    

    VB 2010

    Monday, September 13, 2010 6:46 PM

Answers

  • brain is working again... figured it out.
    • Marked as answer by temlehdrol Monday, September 13, 2010 7:26 PM
    Monday, September 13, 2010 7:26 PM