This tutorial will show how to display the latest entries to a database, using a Repeater Control. VB version.
Displaying the last entries to the database (the newest ones) is rather simple. We can order the select statement using a SQL statement, and just select the last 5, 10, 20, etc.
First, we need this line:
| Imports System.Data.SqlClient |
I just signed up at Server Intellect and couldn't be more pleased with my Windows Server! Check it out and see for yourself.
Next, we create a Repeater control to display the data:
<form id="form1" runat="server"> <div> <asp:Repeater ID="Repeater1" runat="server"> <HeaderTemplate></HeaderTemplate> <ItemTemplate>ID: <%#DataBinder.Eval(Container.DataItem, "theID")%><br /> Name: <%#DataBinder.Eval(Container.DataItem, "theName") %><br /> City: <%#DataBinder.Eval(Container.DataItem, "theCity")%><hr width="50px" /> </ItemTemplate> <FooterTemplate></td></FooterTemplate> </asp:Repeater> </div> </form> |
I just signed up at Server Intellect and couldn't be more pleased with my Windows Server! Check it out and see for yourself.
Then, using a SQL Statement, we select the last 5 entries to the database. This 5 can be changed to 10, 20, etc. Depending on the needs and database size.
The code-behind would look something like this:
Imports System Imports System.Data Imports System.Configuration Imports System.Web Imports System.Web.Security Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Web.UI.WebControls.WebParts Imports System.Web.UI.HtmlControls Imports System.Data.SqlClient
Partial Public Class _Default
Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim cmd As New SqlCommand("SELECT TOP 5 * FROM [tblOne] ORDER BY [tblOne].theID DESC", New SqlConnection(ConfigurationManager.AppSettings("ConnString"))) cmd.Connection.Open()
Repeater1.DataSource = cmd.ExecuteReader() Repeater1.DataBind()
cmd.Connection.Close() cmd.Connection.Dispose() End Sub End Class |
Looking for the C#.NET 2005 Version? Click Here!
Looking for more ASP.NET Tutorials? Click Here!