web 2.0

ASP.NET(vb.net) & Repeater - Microsoft Access (.mdb) - System.Data.OleDb

ASP.NET(vb.net) & Repeater - Microsoft Access (.mdb) - System.Data.OleDb Example scripts how to use Repeater control in asp.net ,  Using Connector System.Data.OleDb namespace is the .NET Framework Data Provider for Access, how to the connect to Microsoft Acces Database.

ShotDev Focus:
- ASP.NET(vb.net) & Repeater - Microsoft Access (.mdb) - System.Data.OleDb

Example

Repeater1.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Repeater1.aspx.vb" Inherits="Repeater1" %></p>
<p><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"></p>
<p><html xmlns="http://www.w3.org/1999/xhtml" ><br>
<head runat="server"><br>
<title>ShotDev.Com Tutorial</title><br>
</head><br>
<body><br>
<form id="form1" runat="server"><br>
<asp:Repeater id="myRepeater" runat="server"><br>
<HeaderTemplate><br>
<table border="1"><br>
<tr><br>
<th>CustomerID</th><br>
<th>Name</th><br>
<th>Email</th><br>
<th>CountryCode</th><br>
<th>Budget</th><br>
<th>Used</th><br>
</tr><br>
</HeaderTemplate><br>
<ItemTemplate><br>
<tr><br>
<td align="center"><asp:Label id="lblCustomerID" runat="server"></asp:Label></td><br>
<td><asp:Label id="lblName" runat="server"></asp:Label></td><br>
<td><asp:Label id="lblEmail" runat="server"></asp:Label></td><br>
<td align="center"><asp:Label id="lblCountryCode" runat="server"></asp:Label></td><br>
<td align="right"><asp:Label id="lblBudget" runat="server"></asp:Label></td><br>
<td align="right"><asp:Label id="lblUsed" runat="server"></asp:Label></td><br>
</tr><br>
</ItemTemplate><br>
<FooterTemplate><br>
<!--<br>
<tr><br>
<th>CustomerID</th><br>
<th>Name</th><br>
<th>Email</th><br>
<th>CountryCode</th><br>
<th>Budget</th><br>
<th>Used</th><br>
</tr><br>
--><br>
</table><br>
</FooterTemplate><br>
</asp:Repeater><br>
</form><br>
</body><br>
</html><br>

Repeater1.aspx.vb

Imports System.Data<br>
Imports System.Data.OleDb<br>
Partial Class Repeater1<br>
Inherits System.Web.UI.Page<br>
Dim objConn As OleDbConnection<br>
Dim objCmd As OleDbCommand</p>
<p>Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load<br>
Dim strConnString As String<br>
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("db/mydatabase.mdb") & ";"<br>
objConn = New OleDbConnection(strConnString)<br>
objConn.Open()</p>
<p>BindData()<br>
End Sub</p>
<p>Protected Sub BindData()<br>
Dim strSQL As String<br>
strSQL = "SELECT * FROM customer"</p>
<p>Dim dtReader As OleDbDataReader<br>
objCmd = New OleDbCommand(strSQL, objConn)<br>
dtReader = objCmd.ExecuteReader()</p>
<p>'*** BindData to Repeater ***'<br>
myRepeater.DataSource = dtReader<br>
myRepeater.DataBind()</p>
<p>dtReader.Close()<br>
dtReader = Nothing<br>
End Sub</p>
<p>Protected Sub myRepeater_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs) Handles myRepeater.ItemDataBound</p>
<p>'*** CustomerID ***'<br>
Dim lblCustomerID As Label = CType(e.Item.FindControl("lblCustomerID"),Label)<br>
IF Not IsNothing(lblCustomerID) Then<br>
lblCustomerID.Text = e.Item.DataItem("CustomerID")<br>
End IF</p>
<p>'*** Name ***'<br>
Dim lblName As Label = CType(e.Item.FindControl("lblName"),Label)<br>
IF Not IsNothing(lblName) Then<br>
lblName.Text = e.Item.DataItem("Name")<br>
End IF</p>
<p>'*** Email ***'<br>
Dim lblEmail As Label = CType(e.Item.FindControl("lblEmail"),Label)<br>
IF Not IsNothing(lblEmail) Then<br>
lblEmail.Text = e.Item.DataItem("Email")<br>
End IF</p>
<p>'*** CountryCode ***'<br>
Dim lblCountryCode As Label = CType(e.Item.FindControl("lblCountryCode"),Label)<br>
IF Not IsNothing(lblCountryCode) Then<br>
lblCountryCode.Text = e.Item.DataItem("CountryCode")<br>
End IF</p>
<p>'*** Budget ***'<br>
Dim lblBudget As Label = CType(e.Item.FindControl("lblBudget"),Label)<br>
IF Not IsNothing(lblBudget) Then<br>
lblBudget.Text = e.Item.DataItem("Budget")<br>
End IF</p>
<p>'*** Used ***'<br>
Dim lblUsed As Label = CType(e.Item.FindControl("lblUsed"),Label)<br>
IF Not IsNothing(lblUsed) Then<br>
lblUsed.Text = e.Item.DataItem("Used")<br>
End IF<br>
End Sub</p>
<p>Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload<br>
objConn.Close()<br>
objConn = Nothing<br>
End Sub</p>
<p>End Class<br>

Create a asp.net file and save to path root-path/dotnet/

Run
http://localhost/dotnet/Repeater1.aspx

Screenshot

ASP.NET(vb.net) & Repeater - Microsoft Access (.mdb) - System.Data.OleDb
.
.
.

Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (No Ratings Yet)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.