Friday, January 16, 2009

Operations on database connection

Opening a Connection:
Before performing any necessary operation, you must open the connection. To support this, the OleDbConnection class is equipped with the Open() method whose syntax is:
Public Overridable Sub Open() Implements IDbConnection.Open
(or)

Dim Conn As System.Data.OleDb.OleDbConnection
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
Conn = New System.Data.OleDb.OleDbConnection
Conn.ConnectionString = "Provider=Microsoft.JET.
OLEDB.4.0;" &
"Data Source=C:\Programs\Exercise.mdb;"
Conn.Open()
End Sub

Closing a Connection:

you should close it to release its resources and make them available to other applications .
To close a connection, the OleDbConnection class provides the Close() method. Its syntax is:
Public Overridable Sub Close() Implements IDbConnection.Close


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim oleConn As System.Data.OleDb.OleDbConnection
oleConn = New System.Data.OleDb.OleDbConnection

oleConn.ConnectionString = "Provider=Microsoft.JET.OLEDB.4.0;" & _
"Data Source=C:\Programs\Exercise.mdb;"
oleConn.Open()

oleConn.Close()
End Sub







Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home