-3

I have a datatable with about 15000 rows that i need to break down in 9999 rows and get the items and do stuff with them and the get next 9999 until all is processed

This is the getdata code

        public DataTable GetData()
    {
        SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["sqlconnection1"].ConnectionString);
        conn.Open();
        string query = "SELECT [number],[surname],[forename],[emailAddress],[taxIdentifier] FROM[Customer]  WITH(NOLOCK) WHERE[CustomerID] IN(SELECT[CustomerID] FROM[Visit] WITH(NOLOCK) WHERE[GamingDate] Between convert(Date, DATEADD(DAY, -365, GETDATE())) AND convert(Date, getdate())) AND(EmailAddress IS NOT NULL) AND(ContactTypes & 1 = 1) AND(HomePropertyID = '2') /*  2= Malmö  3=Göteborg  4=Stockholm  */ AND(LEN(TaxIdentifier) = '12')";
        SqlCommand cmd = new SqlCommand(query, conn);

        DataTable dt = new DataTable();
        dt.Load(cmd.ExecuteReader());
        conn.Close();
        return dt;


    }

Then i dont have anymore code to handle the data Every row has number,surname,forename,email,tax that i need to use

My question is: How do i get 9999 rows from the datatable? How do i get next 9999 rows until all rows are being processed?

Hope you understand my need and can help me

Thanks

Charlieface
  • 52,284
  • 6
  • 19
  • 43
Ace2874
  • 25
  • 7
  • You've failed to actually ask a question. What part are you stuck on? – ProgrammingLlama Sep 01 '23 at 09:12
  • https://stackoverflow.com/a/10639172/529282 would do – Martheen Sep 01 '23 at 09:12
  • I dont know how to get 9999 from the datatable, do things, then get the next 9999 @Martheen, is it better to do that from the sql query – Ace2874 Sep 01 '23 at 09:25
  • Usually, it's better to do the paging on the SQL, though you can also page on the app side either with regular loops or Linq paging (it can work on the SQL connection itself, or on memory). But as pointed out, you haven't really ask a question here, we don't know what you're actually trying to do, show us your attempt – Martheen Sep 01 '23 at 09:54
  • 1
    Does this answer your question? [Is there any better option to apply pagination without applying OFFSET in SQL Server?](https://stackoverflow.com/questions/70519518/is-there-any-better-option-to-apply-pagination-without-applying-offset-in-sql-se) – Charlieface Sep 01 '23 at 11:28
  • Side note: you are missing `using` on your connection and adapter. Do not use `NOLOCK`, it has serious data integrity implications. – Charlieface Sep 01 '23 at 11:29

0 Answers0