How to move the data reader
-
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)
-
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)
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.
-
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.
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)
-
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)
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.
-
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.