使用多个DataView还是SQL语句? [英] Use Multiple DataViews Or SQL statement?

查看:59
本文介绍了使用多个DataView还是SQL语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将这个问题发送给专家(你们:-)以获得一些反馈.我有一组导入到数据表中的数据.每个记录然后一次显示给用户.我想合并一些SQL查询功能. 这是我需要的指导.

I'm putting this question out to the experts (you guys :-) ) for some feedback. I have a set of data that is imported into a Datatable. Each record is then displayed to the user one at a time. I would like to incorporate some SQL querying functionality. This is where I need some guidance.

 

我最初的想法是拥有一个SQL查询的数组列表,当用户更改过滤器时,我将执行该查询并重新填充Datatable.显然,这个新的过滤后的数据将是原始信息的子集.这将需要多个 调用数据库.

My initial thought was to have an array list of SQL queries, and when the user changed a filter I would execute that query and repopulate the Datatable. Obviously this new filtered data would be a subset of the original information. This would require multiple calls to the database.

但是,我读到有关DataView的信息,看来这就是它们的目的.显示数据表的多个视图.但是,我无法弄清楚如何限制将哪些字段选择/复制到DataView中.我了解如何过滤哪些行 已检索,但我想允许我的用户控制哪些列也是可见的.

However, I read about DataViews and it seems like that is their purpose. To display multiple views of a DataTable. However, I am unable to figure out how to limit which fields are selected/copied into the DataView. I understand how to filter which rows are retrieved, but I want to allow my user to control which Columns are visible also.

 

所以我的问题是:为了向用户提供控制返回的列和行的能力-我应该使用SQL语句并重新填充DataTable,还是应该使用DataViews(如果这样,我该如何过滤列)?  

So my question is: In order to provide my user with the ability to control the Columns and Rows returned- should I use SQL statements and repopulate the DataTable OR should I use DataViews (and if so how do I filter Columns)? 

我应该注意,我不提前知道字段名称,因为数据源会随着时间变化.感谢您的输入

I should note that I do not know the field names ahead of time, as the datasource can change over time. Thanks for the input

推荐答案

您可以尝试的一件事是:将数据集提取到应用程序中的本地dataTable中.然后,使用linq查询作为来自该本地dataTable的数据源以获取您的Dataview.我已经使用linq查询作为datagridview控件的数据源,所以这 可能/应该适用于dataview控件.否则,您可以使用列表对象,并仅用用户指定的列填充此列表,并显示该列表.

One thing you could try is this: pull a dataset into a local dataTable in your app.  Then use a linq query as a datasource from this local dataTable for your Dataview.  I have used linq queries as a datasource for a datagridview control, so this might/should work for a dataview control.  Else you could use a list object and populate this list with only the columns specified by the user and display that.

 


这篇关于使用多个DataView还是SQL语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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