如何快速从数据库加载数据表。 [英] How to load datatable from database fastly.
问题描述
我非常沮丧,在我的应用程序中,我使用数据适配器来填充数据表但是需要花费更多的时间来填充数据表。在我的应用程序场景中,我想要数据表和SQL Server管理工作室中的完整数据,只需几秒钟即可显示数据。
我尝试过datareader和dataadapter,但需要花费更多时间。目前的记录大小是10000+,它可能会增加,所以现在它需要2-4分钟,如果数据库记录增加,那么将需要更多的时间。我的项目仅在C#2.0中开发。
我使用下面的填充数据表代码。我还尝试使用数据加载方法和datareader。
I am very frustrated that in my application I am using data adapter to fill datatable but it is taking much more time to fill the datatable. In my application scenario I want full data in datatable and in SQL Server management studio it takes only seconds to show the data.
I have tried datareader and dataadapter but it taking more time. Current record size is 10000+ and it may increase so now its taking 2-4 minuts and if database records increase then it will take more time. My project developed in C#2.0 only.
I am using below code for fill datatable. I also tried with datatable load method with datareader.
SqlConnection connection=new SqlConnection("connectionString");
connection.Open();
SqlCommand cmd = new SqlCommand("StoredProcedureName", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@param1", 16));
cmd.Parameters.Add(new SqlParameter("@ID", 341));
cmd.Parameters.Add(new SqlParameter("@LOCATION", "Bank Street"));
cmd.Parameters.Add(new SqlParameter("@NAME", "Prince"));
DataTable dt = new DataTable();
new SqlDataAdapter(cmd).Fill(dt);
connection.close();
请给我更好的解决方案。
在此先感谢:)
Please give me better solution for it.
Thanks in Advance :)
推荐答案
在数据表中加载大量数据不是推荐的做法。使用分页或过滤器以避免出现内存问题。
FYI
使用.net Datatable的最佳方式,数据量巨大 [ ^ ]
改善一切 [ ^ ]
扩展ADO.NET DataTables [ ^ ]
加载多个大型ADO.NET DataTables / DataReaders - 性能改进 [ ^ ]
为什么我不在我的ASP.NET应用程序中使用数据集 [ ^ ]
Loading that much data in a datatable is not a recommended practice. Use paging or filters to avoid endup with memory issues.
FYI
Best way to use .net Datatable with a huge data[^]
Improve Everything[^]
Scaling ADO.NET DataTables[^]
Loading multiple large ADO.NET DataTables/DataReaders - Performance improvements[^]
Why I Don't Use DataSets in My ASP.NET Applications[^]
这篇关于如何快速从数据库加载数据表。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!