Access stored procedures are desirable because you know they work and you don't have to mess around with building the SQL string in the codebehind file. Here's a VB example of filling a datagrid called dgMT.
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Public Class Class1
Inherits Page
Protected WithEvents dgMT As System.Web.UI.WebControls.DataGrid
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim objConnect As New OleDbConnection("PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & HttpContext.Current.Server.MapPath("\db\xyz.mdb"))
Dim cmdTherapists As OleDbCommand
Dim objDataReader As OleDbDataReader
cmdTherapists = New OleDbCommand
With cmdTherapists
.Connection = objConnect
.CommandType = CommandType.StoredProcedure
.CommandText = "QSEL_ABC"
.Connection.Open()
objDataReader = .ExecuteReader()
Me.dgMT.DataSource = objDataReader
Me.dgMT.DataBind()
.Connection.Close()
End With
End Sub
End Class |