数据源非常大时的DataSet用法?

时间:2022-12-30 15:50:26

I have read several MS articles about when to use DataSets in conjuration with a database from within a WinForms application. I certainly like the ease of use DataSets offer, but have a few concerns when using them with a large data source. I want to use a SQLite database to locally store processed web log information. Potentially this could result in tens of thousands of rows of data.

我已经阅读了几篇关于何时使用DataSets与WinForms应用程序中的数据库结合使用的MS文章。我当然喜欢DataSet提供的易用性,但在使用大数据源时会有一些问题。我想使用SQLite数据库本地存储已处理的Web日志信息。这可能导致数万行数据。

When a DataSet is filled via a database table, does it end up containing ALL the data from the database, or does it contain only a portion of data from the database?

当通过数据库表填充DataSet时,它最终是否包含数据库中的所有数据,还是仅包含数据库中的一部分数据?

Could I use a DataSet to add rows to the database, perform an Update for example, somehow 'clear' what the DataSet is holding in memory, then perform additional row adding?

我可以使用DataSet向数据库添加行,例如执行更新,以某种方式'清除'DataSet在内存中保存的内容,然后执行其他行添加?

So is it possible to essentially manage what a DataSet is currently holding in memory? If a DataSet represents a table that contains 100,000 rows, does that mean all 100,000 rows need to be loaded from the database into memory before it is even usable?

那么基本上可以管理DataSet当前在内存中保存的内容吗?如果DataSet表示包含100,000行的表,这是否意味着在数据库甚至可用之前,需要将所有100,000行从数据库加载到内存中?

Thanks.

1 个解决方案

#1


2  

You have very important points here. These points were raised at the beginning of .Net, when we suddenly moved to disconnected state introduced in .NET.

你在这里有非常重要的观点。当我们突然转向.NET中引入的断开连接状态时,这些要点在.Net开始时提出。

The answer to your problem is paging. You need to manually code your grid or other displaying device (control) so it queries database in chunks. For example, you have a control (but not grid) that has fields and a scroll. You give your scroll 201 clicks. On 200 clicks, it scrolling through 200 records, on click # 201, it queries database for 200 more. May be, add some logic to remove 200 records, when number of them in the dataset reaches 1000. This is just an example.

您的问题的答案是分页。您需要手动编码网格或其他显示设备(控件),以便以块的形式查询数据库。例如,您有一个控件(但不是网格),它有字段和滚动。您点击滚动201。在点击200次后,它滚动浏览200条记录,点击#201,它向数据库查询200多条记录。可能是,当数据集中的数量达到1000时,添加一些逻辑来删除200条记录。这只是一个例子。

To save data you can add it to this same DataSet/DataTable. There are few ways of doing it. DataSet/DataTable have capabilities to identify new or edited rows, relationships, etc. On a serious systems, Entity Lists encapsulate Datatables and provide customizations.

要保存数据,可以将其添加到同一个DataSet / DataTable中。这样做的方法很少。 DataSet / DataTable具有识别新的或编辑的行,关系等的功能。在严肃的系统上,实体列表封装了数据表并提供自定义。

May be you want to look into Entity Framework capability. I am not sure if this functionality was included there.

您可能希望了解实体框架功能。我不确定是否包含此功能。

Basically, for some simple application with small data it is Ok to use out of box ADO.net. But in a serious system, normally, there is a lot of ground work with ADO.NET to provide solid Data Access Layer and more additional work to create favorable user experience. In this case, it would be loading data in chunks because if you load 100K records, user will have to wait to load first, then it will be hard to scroll through all of them.

基本上,对于一些使用小数据的简单应用程序,可以使用开箱即用的ADO.net。但是在一个严肃的系统中,通常,ADO.NET有很多基础工作可以提供可靠的数据访问层以及更多额外的工作来创建有利的用户体验。在这种情况下,它将以块的形式加载数据,因为如果加载100K记录,用户将不得不等待首先加载,然后很难滚动所有这些记录。

In the end, you need to look at what your application is, and what it is for, and what will be satisfactory or not satisfactory for the user.

最后,您需要查看您的应用程序是什么,它的用途,以及对用户满意或不满意的内容。

#1


2  

You have very important points here. These points were raised at the beginning of .Net, when we suddenly moved to disconnected state introduced in .NET.

你在这里有非常重要的观点。当我们突然转向.NET中引入的断开连接状态时,这些要点在.Net开始时提出。

The answer to your problem is paging. You need to manually code your grid or other displaying device (control) so it queries database in chunks. For example, you have a control (but not grid) that has fields and a scroll. You give your scroll 201 clicks. On 200 clicks, it scrolling through 200 records, on click # 201, it queries database for 200 more. May be, add some logic to remove 200 records, when number of them in the dataset reaches 1000. This is just an example.

您的问题的答案是分页。您需要手动编码网格或其他显示设备(控件),以便以块的形式查询数据库。例如,您有一个控件(但不是网格),它有字段和滚动。您点击滚动201。在点击200次后,它滚动浏览200条记录,点击#201,它向数据库查询200多条记录。可能是,当数据集中的数量达到1000时,添加一些逻辑来删除200条记录。这只是一个例子。

To save data you can add it to this same DataSet/DataTable. There are few ways of doing it. DataSet/DataTable have capabilities to identify new or edited rows, relationships, etc. On a serious systems, Entity Lists encapsulate Datatables and provide customizations.

要保存数据,可以将其添加到同一个DataSet / DataTable中。这样做的方法很少。 DataSet / DataTable具有识别新的或编辑的行,关系等的功能。在严肃的系统上,实体列表封装了数据表并提供自定义。

May be you want to look into Entity Framework capability. I am not sure if this functionality was included there.

您可能希望了解实体框架功能。我不确定是否包含此功能。

Basically, for some simple application with small data it is Ok to use out of box ADO.net. But in a serious system, normally, there is a lot of ground work with ADO.NET to provide solid Data Access Layer and more additional work to create favorable user experience. In this case, it would be loading data in chunks because if you load 100K records, user will have to wait to load first, then it will be hard to scroll through all of them.

基本上,对于一些使用小数据的简单应用程序,可以使用开箱即用的ADO.net。但是在一个严肃的系统中,通常,ADO.NET有很多基础工作可以提供可靠的数据访问层以及更多额外的工作来创建有利的用户体验。在这种情况下,它将以块的形式加载数据,因为如果加载100K记录,用户将不得不等待首先加载,然后很难滚动所有这些记录。

In the end, you need to look at what your application is, and what it is for, and what will be satisfactory or not satisfactory for the user.

最后,您需要查看您的应用程序是什么,它的用途,以及对用户满意或不满意的内容。