Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to move the data reader

How to move the data reader

Scheduled Pinned Locked Moved ASP.NET
databasesql-serversysadmintutorialquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nour123
    wrote on last edited by
    #1

    Hi All I have a data reader that reads data from an SQL Server table, I need to move the cursor of the data reader to the last record.. (there is no dr1.movelast) How could it be? Luv ya

    Nour Abdel-Salam... A Trainer and a Web Developer in Jedda Int'l Computer Center(JICC)

    C 1 Reply Last reply
    0
    • N nour123

      Hi All I have a data reader that reads data from an SQL Server table, I need to move the cursor of the data reader to the last record.. (there is no dr1.movelast) How could it be? Luv ya

      Nour Abdel-Salam... A Trainer and a Web Developer in Jedda Int'l Computer Center(JICC)

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      I am guessing your best bet is to read each row until you come to the last one, then use the last one you read. A better way would be to write SQL that returns just the data you need.

      Christian Graus Driven to the arms of OSX by Vista.

      N 1 Reply Last reply
      0
      • C Christian Graus

        I am guessing your best bet is to read each row until you come to the last one, then use the last one you read. A better way would be to write SQL that returns just the data you need.

        Christian Graus Driven to the arms of OSX by Vista.

        N Offline
        N Offline
        nour123
        wrote on last edited by
        #3

        Dear Here is the code cm.CommandText = "select * From News" dr = cm.ExecuteReader() If dr.HasRows = False Then Label2.Text = "No News..." End If Do While dr.Read 'here is the problem, I need the data for the last record ' and this code gives me the first one Label2.Text = dr.GetString(1) Label3.Text = dr.GetString(2) Label4.Text = dr.GetString(4) Label5.Text = dr.GetString(5) Label6.Text = dr.GetString(7) Label7.Text = dr.GetString(8) Loop Regards...

        Nour Abdel-Salam... A Trainer and a Web Developer in Jedda Int'l Computer Center(JICC)

        C 1 Reply Last reply
        0
        • N nour123

          Dear Here is the code cm.CommandText = "select * From News" dr = cm.ExecuteReader() If dr.HasRows = False Then Label2.Text = "No News..." End If Do While dr.Read 'here is the problem, I need the data for the last record ' and this code gives me the first one Label2.Text = dr.GetString(1) Label3.Text = dr.GetString(2) Label4.Text = dr.GetString(4) Label5.Text = dr.GetString(5) Label6.Text = dr.GetString(7) Label7.Text = dr.GetString(8) Loop Regards...

          Nour Abdel-Salam... A Trainer and a Web Developer in Jedda Int'l Computer Center(JICC)

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Well, like I said, fix your code. You are selecting news without specifying any sort order. I assume they will come out by Id. So, select by Id in descending order. If you don't have an Id, add one. This code is bad on a number of levels, I would recommend you do some reading on things like writing a proper data layer, giving your variables proper names so that your code is maintainable, etc.

          Christian Graus Driven to the arms of OSX by Vista.

          N 1 Reply Last reply
          0
          • C Christian Graus

            Well, like I said, fix your code. You are selecting news without specifying any sort order. I assume they will come out by Id. So, select by Id in descending order. If you don't have an Id, add one. This code is bad on a number of levels, I would recommend you do some reading on things like writing a proper data layer, giving your variables proper names so that your code is maintainable, etc.

            Christian Graus Driven to the arms of OSX by Vista.

            N Offline
            N Offline
            nour123
            wrote on last edited by
            #5

            thanks alot it works luv ya **

            Nour Abdel-Salam... A Trainer and a Web Developer in Jedda Int'l Computer Center(JICC)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups