This tutorial will show how to display the latest entries to a database, using a Repeater Control. VB version.
We chose Server Intellect for its dedicated servers, for our web hosting. They have managed to handle virtually everything for us, from start to finish. And their customer service is stellar.
Looking for the C#.NET 2005 Version? Click Here!
Looking for more ASP.NET Tutorials? Click Here!
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 |
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> |
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!
If you're ever in the market for some great Windows web hosting, try Server Intellect. We have been very pleased with their services and most importantly, technical support.