Pulling out 10 last posts in forum (access db)

Discussion in 'ASP .Net' started by Daniel Jahro via DotNetMonster.com, Feb 3, 2005.

  1. 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
     
    Daniel Jahro via DotNetMonster.com, Feb 3, 2005
    #1
    1. Advertisements

  2. 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/>

    automatically get accending numbers. The first vertical row (?) with the
    numbers are named "Topic_ID".
     
    Gopal \(FMS, Inc.\), Feb 3, 2005
    #2
    1. Advertisements

  3. Heh, i guess, but im pritty new to this, so could you by any chance be somewhat more specific? :)
     
    Daniel Jahro via DotNetMonster.com, Feb 3, 2005
    #3
  4. 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>
     
    John Timney \(ASP.NET MVP\), Feb 3, 2005
    #4
  5. Where? :)
     
    Daniel Jahro via DotNetMonster.com, Feb 3, 2005
    #5
  6. 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
     
    Patrick Olurotimi Ige, Feb 3, 2005
    #6
  7. Thanks! Im trying to get it to work..
     
    Daniel Jahro via DotNetMonster.com, Feb 4, 2005
    #7
  8. Hi Daniel Jahro,
    Good u are trying..'
    Any more questions let me know.
    Patrick
     
    Patrick Olurotimi Ige, Feb 4, 2005
    #8
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.