473,386 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How can I read only certain records with SqlDataReader

Hi,

Hi,

I have a table with 100,000 records but I only want to read 250. I know the row number of the 250 records that I have to read and so I want to avoid reading all the previous records each time. For example, if I want to read rows 60,001 to 60,250 how would I do that? Is there any way of doing it without reading the previous 60,000 rows?
Is sqlDataReader the right choice or should I be using something else?

Below is my code:



Expand|Select|Wrap|Line Numbers
  1. public class cRead_CoveringElementType_Variation_IntoArray
  2. {
  3.  
  4. public static void mRead_CoveringElementType_Varation_IntoArray(int liFromBlock, int liToBlock)
  5. {
  6.  
  7. int liRowNo = 0;
  8. int liMiscLp = 0;
  9.  
  10. string strCommSelect = "";
  11.  
  12. strCommSelect = "SELECT * FROM tbl_COVERING_and_KType";
  13.  
  14. string strConnection = @"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\CombinatoRoyX\DataBase\dbCoveringType_Sorted.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"; // User Id=sa;Password=Elena_501_Pogutz; This is the PW
  15. SqlConnection oConnection = new SqlConnection(strConnection);
  16. SqlCommand oCommand = new SqlCommand(strCommSelect, oConnection);
  17.  
  18. oCommand.Connection.Open();
  19.  
  20. SqlDataReader mySqlDataReader = oCommand.ExecuteReader();
  21.  
  22.  
  23. int liRowToRead = 0;
  24.  
  25.  
  26. while (mySqlDataReader.Read())
  27. {
  28.  
  29. liRowNo++;
  30.  
  31. if (liRowNo >= liFromBlock && liRowNo <= liToBlock)
  32. {
  33.  
  34. liRowToRead++;
  35.  
  36.  
  37. for (liMiscLp = 1; liMiscLp <= 2 * aGV.K; liMiscLp++) aGV.Cov_Var[liRowToRead, liMiscLp] = mySqlDataReader.GetInt32(liMiscLp);
  38.  
  39. }
  40.  
  41. }
  42.  
  43.  
  44. mySqlDataReader.Close();
  45. oConnection.Close();
  46.  
  47.  
  48.  
  49.  
  50.  
  51. }
  52.  
  53. }
Thanks
Roy Gourgi
Jul 12 '11 #1
1 1873
Rabbit
12,516 Expert Mod 8TB
Assuming you have some sort of unique ID, you could just do
Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM tableName
  3. WHERE UniqueID BETWEEN 60001 AND 60250
Jul 12 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Miguel Orrego | last post by:
Hi, I have a site on our intranet that takes information from one database, lets the user see it and if they want to lets then write it into another database. However, only recently with...
2
by: Lupina | last post by:
I want to read certain node from xml file by the ID. It means taht I know the ID of person, and I want read all data that person (eg: name,mail...). persons.xml <?xml version="1.0"?>...
3
by: Tim Graichen | last post by:
In subFormC, I would like to display only those records that have TrialDate and CompanyCode equal to TrialDate and CompanyCode in subFormB. Can somebody please help me? Thanks Tim
0
by: perryche | last post by:
This may have been missed, so I appoglize if I am reposting this. (I also want to thank Larry and James for their previous help) All, Table1 Field1 Field2 Field3 Field4 ......
3
by: Blake | last post by:
Hello, I have a database at work that keeps an inventory of cameras by location. Every week I get a repair estimate sheet that lists cameras by serial number that need to be repaired. This list...
5
by: Twanne | last post by:
Hi I wrote this function: Function UpdateLongfunctieFEVFVC() Set db = CurrentDb Dim percfev As Double Dim percfvc As Double Set rst = db.OpenRecordset("SELECT eadnr, datum,...
3
by: Coll | last post by:
I have a form that had been setup with a combo box. You'd select a value from the combo box and a query would open and display matching records. I now need to remove the combo box and set up a text...
3
by: skkuan | last post by:
Hi C# experts Said I have the following hexadecimal files 00000160h: 00 00 00 00 CD CD 00 30 39 21 03 50 00 02 0F 2E; 00000170h: --- I need to read the bytes starting from CD. I am not...
0
by: malukj | last post by:
Hi, New to all this. I'm returning records by first letter, works fine by returning all records but I want to only return the records where notes=b but I just can't get it to work I'm using...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.