如何在C#中从sqlite数据库加载大量数据 [英] How to load large amount of data from sqlite database in C#

查看:546
本文介绍了如何在C#中从sqlite数据库加载大量数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的WPF应用程序中使用SQLite作为数据库,需要从数据库加载大量数据,当我使用select * from tablename加载数据时需要很长时间。任何人都可以帮我快速获取数据吗?



我尝试过:



我使用普通的Select查询从SQLite DB中获取数据

解决方案

这将取决于你如何加载它,以及你是什么一旦加载就用它做。

如果使用DataAdapter,那么在DataTable或DataSet完全加载之前命令执行不会返回 - 大量数据可能需要很长时间。

如果使用DataReader,命令执行几乎立即返回,但每行必须按顺序访问,每次访问所需的时间比从DataTable访问相同数据要长一些。



如果您逐个处理行,那么DataReader可能是更好的选择,因为控件会立即返回。如果您正在加载DataTable以便可以将大量数据转储到UI控件中,那么您就会导致自己的问题并创建一个总是很慢并且被用户讨厌的应用程序。

我们无法分辨。



您的数据也可能包含您不使用的大型对象:SELECT *会返回所有内容,因此如果是列包含您不需要的图像,您可以通过仅指定您需要的列来加快速度 - 无论如何这被认为是一种很好的做法。



但是基本上,这取决于你:我们不知道你如何获取你的数据,它有多少,或者当你获取它时你用它做什么 - 我们无法查看你的应用程序或数据来查找!

I am using SQLite as Database for my WPF application, need to load Large amount of data from Database, When I use select * from tablename to load data it is taking long time. Can any one help me to fetch the data as fast as?

What I have tried:

I used normal Select query to fetch data from SQLite DB

解决方案

It's going to depend on how you are loading it, and what you are doing with it once loaded.
If you use a DataAdapter, then the command execution does not return until the DataTable or DataSet is completely loaded - with large amounts of data this can take quite a while.
If you use a DataReader, the command execution returns almost immediately, but each row must then be accessed sequentially and each access takes a little longer than accessing the same data from a DataTable.

If you are processing rows one-by-one, then a DataReader may be a better choice as control is returned immediately. If you are loading a DataTable so that you can dump a huge amount of data into a UI control, then you are causing your own problem and creating an app that is always going to be slow, and hated by your users.
We can't tell.

It's also possible that your data includes large objects that you don't use: SELECT * returns everything, so if a column contains images that you don't need, you can probably speed things up by specifying only the columns you do need - this is considered a good practice anyway.

But basically, it's up to you: we have no idea how you fetch your data, how much of it there is, or what you do with it when you have fetched it - and we can't look at your app or data to find out!


这篇关于如何在C#中从sqlite数据库加载大量数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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