Pulling out 10 last posts in forum (access db)

  • Thread starter Daniel Jahro via DotNetMonster.com
  • Start date
D

Daniel Jahro via DotNetMonster.com

Hi!

Im trying to pull out the last ten posts in a access dg (*.mdb). Whats the best way to do it?

All posts are located in a table named "tblTopic" and the posts automatically get accending numbers. The first vertical row (?) with the numbers are named "Topic_ID".

Any ideas?

Thanks in advance!
-daniel
 
G

Gopal \(FMS, Inc.\)

Select top 10 * from tblTopic order by Topic_ID desc

You need to run the above query from an aspx page and populate a datagrid.

Hope this gets you on the right track.
--
Gopal Rangaswamy
Microsoft Certified Solutions Developer
FMS, Inc.
<http://www.fmsinc.com/consulting>
<http://www.fmsinc.com/dotnet/SourceBook/>

Daniel Jahro via DotNetMonster.com said:
Hi!

Im trying to pull out the last ten posts in a access dg (*.mdb). Whats the best way to do it?

All posts are located in a table named "tblTopic" and the posts
automatically get accending numbers. The first vertical row (?) with the
numbers are named "Topic_ID".
 
D

Daniel Jahro via DotNetMonster.com

Heh, i guess, but im pritty new to this, so could you by any chance be somewhat more specific? :)
 
J

John Timney \(ASP.NET MVP\)

The code below might help.....change the database name and it might just
work.....

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director


<%@ Page Language="VB"%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<script language="VB" runat="server">
Sub Page_Load(Src as object, E as EventArgs)

Dim objConnection As OleDbConnection
Dim objCommand As OleDbCommand
Dim objDataReader As OleDbDataReader
Dim strSQLQuery As String

objConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=" & Server.MapPath("database.mdb") & ";")

strSQLQuery = "Select top 10 * from tblTopic order by Topic_ID desc"

objCommand = New OleDbCommand(strSQLQuery, objConnection)

objConnection.Open()

objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection)

resultsGrid.DataSource = objDataReader
resultsGrid.DataBind()

End Sub

</script>

<html>
<body>

<asp:DataGrid id="resultsGrid" runat="server"
cellspacing="1"
cellpadding="2"
HeaderStyle-Font-Bold="True"
ToolTip="This is Cool!"
MaintainViewState="false"
/>

</body>
</html>
 
P

Patrick Olurotimi Ige

Daniel with the code John gave u below:-
Change this 2 lines:-

objConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=" & Server.MapPath("database.mdb") & ";")

strSQLQuery = "Select top 10 * from tblTopic order by Topic_ID desc"

change the database.mdb to your database name!
And thats it..
Hope it helps
Patrick





Sub Page_Load(Src as object, E as EventArgs)

Dim objConnection As OleDbConnection
Dim objCommand As OleDbCommand
Dim objDataReader As OleDbDataReader
Dim strSQLQuery As String

objConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=" & Server.MapPath("database.mdb") & ";")

strSQLQuery = "Select top 10 * from tblTopic order by Topic_ID desc"

objCommand = New OleDbCommand(strSQLQuery, objConnection)

objConnection.Open()

objDataReader =
objCommand.ExecuteReader(CommandBehavior.CloseConnection)

resultsGrid.DataSource = objDataReader
resultsGrid.DataBind()

End Sub
 
P

Patrick Olurotimi Ige

Hi Daniel Jahro,
Good u are trying..'
Any more questions let me know.
Patrick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top