Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have the following function under my update button to save changes in my datagridview back into SQL Server. The problem here is my table is over 40 000 records and it takes forever to fill to dataset every time the button is pressed.

C#
try
          {
              SqlConnection con = new SqlConnection(constr);
              con.Open();

              SqlDataAdapter adapter = new SqlDataAdapter();
              adapter.SelectCommand = new SqlCommand("SELECT * FROM trips", con);
              SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
              adapter.Fill(dt);
              adapter.Update(dt);

              MessageBox.Show("Changes Saved", "Updating...", MessageBoxButtons.OK, MessageBoxIcon.Information);
              con.Close();
          }
          catch (Exception ex)
          {
              MessageBox.Show(ex.ToString());
          }
          finally { lblCount.Text = "Total Records Displayed: " + dgvTrips.Rows.Count.ToString(); }


What I have tried:

Is there a workaround for this?
Posted
Updated 23-Jun-16 21:53pm

Fixed it by prompting to filter the data first before loading the records rather than applying the filter afterwards.
 
Share this answer
 
40,000 records - in a datagridview - dont you like your users ? (it smells of 'bad design')

can you either

a) 'page load' your data or

b) load the records in a background thread while the program is starting up (I use this technique to get data from a FTP server - by the time the user gets to the tab-page where they need it, hey-presto its there)
 
Share this answer
 
Comments
emilius94 24-Jun-16 2:58am    
Not all records get displayed at once. I'll give the background thread a try. Thanks.
emilius94 24-Jun-16 17:11pm    
By the way... Your dick smells of bad design you f***ing c*** sucker lol

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900