DataAdapter.Fill方法太慢 [英] DataAdapter.Fill too slow
问题描述
我知道DataAdapters有性能问题,但有可能会更快周围没有任何办法?目前,该DataAdapter.Fill方法方法正在对3000条记录,这是我的应用程序太慢了5-6秒。如果我删除填写
行,只是执行SQL(使用SQLCE),它需要20毫秒,所以我猜查询是没有问题的。我试着加入 BeginLoadData
的数据表,但它使对性能没有区别。
I know DataAdapters have performance issues, but are there any ways around it that might be faster? At the moment, the DataAdapter.Fill method is taking 5-6 seconds on 3000 records, which is too slow for my app. If I remove the Fill
line and just execute the SQL (using SQLCE), it takes 20 milliseconds, so I'm guessing the query isn't the problem. I've tried adding BeginLoadData
on the datatable, but it makes no difference to the performance.
using (SqlCeConnection con = new SqlCeConnection(conString))
{
con.Open();
using (SqlCeDataAdapter dAdapter= new SqlCeDataAdapter())
{
using (SqlCeCommand com = new SqlCeCommand(query, con))
{
com.Parameters.Add("uname", textBox1.Text);
dAdapter.SelectCommand = com;
dAdapter.SelectCommand.Connection = con;
DataTable dTable = new DataTable();
dAdapter.Fill(dTable);
dataGridView1.DataSource = dTable;
}
}
}
是否有更好的方法来填充的DataGridView或加快填写
方法?
Are there better ways to fill a DataGridView or speed up the Fill
method?
推荐答案
您可以绑定在DataGridView到的DataReader
代替,但它可能不会好很多,因为装载3000行到一个DataGridView只是没有迅速。
You could bind the DataGridView to a DataReader
instead, but it may not be much better, since loading 3000 rows into a DataGridView just isn't speedy .
这篇关于DataAdapter.Fill方法太慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!