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
- public class cRead_CoveringElementType_Variation_IntoArray
- {
- public static void mRead_CoveringElementType_Varation_IntoArray(int liFromBlock, int liToBlock)
- {
- int liRowNo = 0;
- int liMiscLp = 0;
- string strCommSelect = "";
- strCommSelect = "SELECT * FROM tbl_COVERING_and_KType";
- 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
- SqlConnection oConnection = new SqlConnection(strConnection);
- SqlCommand oCommand = new SqlCommand(strCommSelect, oConnection);
- oCommand.Connection.Open();
- SqlDataReader mySqlDataReader = oCommand.ExecuteReader();
- int liRowToRead = 0;
- while (mySqlDataReader.Read())
- {
- liRowNo++;
- if (liRowNo >= liFromBlock && liRowNo <= liToBlock)
- {
- liRowToRead++;
- for (liMiscLp = 1; liMiscLp <= 2 * aGV.K; liMiscLp++) aGV.Cov_Var[liRowToRead, liMiscLp] = mySqlDataReader.GetInt32(liMiscLp);
- }
- }
- mySqlDataReader.Close();
- oConnection.Close();
- }
- }
Roy Gourgi