Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

how should i close oledbconnection declared in a module

$
0
0
I have an oledbconnection called myConnection declared in a module. and it is called in a form.
how should close the oledbconnection myConnection ? should I close it in the module itself? if yes how.?
the code for the form is:

Code:

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim Str As String = "SELECT * FROM Login WHERE username='" & txtUsername.Text & "' AND password='" & txtPassword.Text & "'"
        Dim cmd As OleDbCommand = New OleDbCommand(Str, DBconnection)
        dr = cmd.ExecuteReader
        If dr.HasRows Then
            MsgBox("successfull")
        Else : MsgBox("incorrect username or password")
        End If

    End Sub

the code for the module is:

Code:


Imports System.Data
Imports System.Data.OleDb
Module Module1


    Friend conString As String
    Public dr As OleDbDataReader


    Public Function DBconnection() As OleDbConnection

        Dim myConnection As New OleDb.OleDbConnection
        conString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source = D:\vb programs\working copy for windows application 4\WindowsApplication4\student.mdb"
        myConnection = New OleDb.OleDbConnection(conString)
        myConnection.Open()
        Return myConnection

    End Function

End Module


Viewing all articles
Browse latest Browse all 13329

Trending Articles