Need to set up a Database connection class to be used throughout a project

I am trying to create a Database Class to be used throughout a project.  I have written the following code.  I am more familiar with ASP coding then I am with VB.net and I am having trouble calling the class properly to be used within the from code.   The error that I am getting is (Type 'SqlConn.Conn' is not defined.').

Thanks



---  Class Code

Public Class SqlConn
    Public Function Conn()
        Dim cnn = New ADODB.Connection
        cnn.ConnectionString = "Provider=SQLOLEDB.1;Password=xxx;Persist Security Info=True;User Id=xxx;Initial Catalog=xxx;Data Source=xxx"
        cnn.CursorLocation = ADODB.CursorLocationEnum.adUseClient
    End Function
End Class


----- Form Code

 Public Sub frmListServEmailer_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim rst As ADODB.Recordset
        Dim strQuery As String
       Dim cnn As SqlConn.conn


        cnn.Open()

        rst = New ADODB.Recordset
        rst.CursorLocation = ADODB.CursorLocationEnum.adUseClient
        rst.LockType = ADODB.LockTypeEnum.adLockReadOnly
        strQuery = "Select idEmailType, fldEmailDescription as [Email Type] from tblEmailType order by idEmailType"
        rst = cnn.execute(strQuery)


        If rst.EOF Then
            rst.Close()
            rst = Nothing
        Else
            Do
                Me.lstEmailType.Items.IndexOf(rst("idEmailType").Value)
                Me.lstEmailType.Items.Add(rst("Email Type").Value)
                rst.MoveNext()
            Loop Until rst.EOF

            rst.Close()
            rst = Nothing
        End If
    End Sub



Richard ComitoDirector of ITAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

natlozCommented:
Here is a sample from one of my projects....see the LOOK HERE labels below

Public Class clsDBConn
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'Returns the connection string being used to access SQL database
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Public Function getStrConn() As String
        Dim strConn As String

               'PRODUCTION EDMAPPS2K1
        'strConn = "User ID=orm;Password=YOURPASSWORD;Initial Catalog=OUTSIDERENTALS;Data Source=EDMAPPS2K1"

        Return strConn
    End Function
End Class




 'Variables and objects
        Dim cDB As clsDBConn = New clsDBConn 'Connection Class <----------LOOK HERE
        Dim strConn As String = cDB.getStrConn 'Get connection string for database <----------LOOK HERE
        Dim oConn As New SqlConnection 'SQL connection object
        Dim intReturnID As Integer 'Return ID from Stored Procedures
        Dim oComm As SqlCommand 'SQL Command object
        Dim bFail As Boolean = False 'Test for failure

        'Validate form has data
        If Me.txtUsername.Text = "" Then
            MsgBox("Please enter a User Name.")
            Me.txtUsername.Focus()
            bFail = True
        Else
            If Me.txtPassword.Text = "" Then
                MsgBox("Please enter a Password.")
                Me.txtPassword.Focus()
                bFail = True
            End If
        End If

        If bFail = False Then 'All is well
            'Connect to SQL server and validate login
            Try
                'Pass connection string to SqlConnection
                oConn.ConnectionString = strConn <----------LOOK HERE

                'SQL Database statements
                oComm = New SqlCommand
                oComm.CommandType = CommandType.StoredProcedure
                oComm.CommandText = "spValidateLogin"
                oComm.Connection = oConn

                'Send in parameters
                oComm.Parameters.Add(New SqlParameter("@varUserName", SqlDbType.VarChar)).Value = Me.txtUsername.Text
                oComm.Parameters.Add(New SqlParameter("@varPassword", SqlDbType.VarChar)).Value = Me.txtPassword.Text

                'Return value from stored procedure
                Dim sParam As SqlParameter
                sParam = New SqlParameter
                sParam.ParameterName = "@ReturnID"
                sParam.SqlDbType = SqlDbType.Int
                sParam.Direction = ParameterDirection.Output
                oComm.Parameters.Add(sParam)

                'Open connection and execute oComm
                oConn.Open() 'Open connection
                oComm.ExecuteNonQuery() 'Execute stored procedure
                intReturnID = oComm.Parameters("@ReturnID").Value 'Get Return value
                oConn.Close() 'Close connection

                'Analyze Return value for errors
                If intReturnID < 0 Then 'All errors are less than 0
                    MsgBox("Invalid Login, please try again.")
                    Me.txtUsername.Focus()
                Else
                    Dim frmMain As frmMain = New frmMain
                    'Set the global variable for user logged in
                    _intUserID = intReturnID

                    'Open Main form and hide Login screen
                    frmMain.Show()
                    Me.Hide()
                End If

            Catch ex As Exception
                MsgBox(ex.ToString)
                MsgBox("Error connecting to SQL Server")
            Finally
                oConn.Close() 'Close connection
            End Try
        End If

        Me.Cursor = System.Windows.Forms.Cursors.Default
    End Sub

End Class
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.