|
Imports System Imports System.Data Imports System.Data.OleDb imports system.web.ui imports system.web.ui.webControls
Namespace YasirNet
Public Class MyBasicClass Inherits UserControl
'Here is my First Function in ASP.Net ConnectNow() which encapsulate the connection code
Public reader As OleDbDataReader Public Function ConnectNow(strSQL AS String) Dim connectString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & Server.MapPath("/myfolder/mydatabase.mdb")
'Create an OleDbConnection object, 'and then pass in the ConnectionString to the constructor. Dim cn As OleDbConnection = New OleDbConnection(connectString)
'Open the connection. cn.Open()
'Use a variable to hold the SQL statement. Dim selectString As String = strSQL
'Create an OleDbCommand object. 'Notice that this line passes in the SQL statement and the OleDbConnection object. Dim cmd As OleDbCommand = New OleDbCommand(selectString, cn)
'Send the CommandText to the connection, and then build an OleDbDataReader. 'Note: The OleDbDataReader is forward-only. reader = cmd.ExecuteReader() End Function
End Namespace |