<%@ Page Inherits="ParentPage" src="Default.aspx.vb" %>
<html><body>
<form runat="server">
<asp:Label id="lblMessage" runat="server" />
<asp:DataGrid id="DataGrid1"
runat="server"
AutoGenerateColumns="True" />
</asp:DataGrid>
</form>
</body></html>
File: Default.aspx.vb
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Data.OleDb
Public Class ParentPage : Inherits Page
public lblMessage as Label
public DataGrid1 as DataGrid
private strConnString as string = "Provider=" & _
"Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=yourDatabase.mdb"
private objConn as new OleDbConnection(strConnString)
sub Page_Load(Sender as Object, e as EventArgs)
if Not Page.IsPostBack then
FillDataGrid()
end if
end sub
private sub FillDataGrid(Optional EditIndex as integer=-1)
dim objCmd as OleDbCommand = new OleDbCommand("select * from tblUsers", objConn)
dim objReader as OleDbDataReader
try
objCmd.Connection.Open()
objReader = objCmd.ExecuteReader
catch ex as OleDbException
lblMessage.Text = "Error retrieving from the database."
end try
DataGrid1.DataSource = objReader
DataGrid1.DataBind()
objReader.Close
objCmd.Connection.Close()
end sub
End Class
|