将datagridview的更改更新为SQL(大型数据库) [英] Update changes of datagridview to SQL (large database)

查看:110
本文介绍了将datagridview的更改更新为SQL(大型数据库)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在更新按钮下有以下功能,可以将datagridview中的更改保存回SQL Server。这里的问题是我的表超过40 000条记录,每次按下按钮都需要永久填充数据集。



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.

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?

推荐答案

通过提示在加载记录之前先过滤数据而不是之后应用过滤器来修复它。
Fixed it by prompting to filter the data first before loading the records rather than applying the filter afterwards.


40,000条记录 - 在datagridview中 - 你不喜欢你的用户吗? (闻起来有'糟糕的设计')



你能否



a)'页面加载'你的数据或



b)在程序启动时加载后台线程中的记录(我使用这种技术从FTP服务器获取数据 - 当用户使用时到达他们需要的标签页,嘿 - presto在那里)
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)


这篇关于将datagridview的更改更新为SQL(大型数据库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆