简体   繁体   English

从现有数据集中添加新数据源以用于本地报告?

[英]Add new Data Source from an existing DataSet for local report?

When using wizard to add a new Data Source to the project, there are 4 options, one goes for Database , one goes for Service , one goes for Object and the last goes for Sharepoint . 使用向导将新数据源添加到项目时,有四个选项,一个用于数据库 ,一个用于服务 ,一个用于对象 ,最后一个用于Sharepoint I'm focusing on Database and Object , these two options are almost the same in how they get data, both of them use SQL query to fetch data, the difference here is Database will get data from a procedure or function stored on the server whereas Object will get data from a method which executes some SQL query remotely. 我专注于DatabaseObject ,这两个选项在获取数据的方式上几乎相同,它们都使用SQL查询来获取数据,这里的区别是Database将从存储在服务器上的过程或函数中获取数据,而对象将从远程执行一些SQL查询的方法中获取数据。 Using two of these options will make me re-create/re-execute my SQL statement to get data, which is very unnecessary because I already have a Dataset filled with data (for displaying in DataGridView), so why the hell do I have to re-execute the exact SQL statement I've executed when filling my Dataset? 使用其中两个选项将使我重新创建/重新执行SQL语句以获取数据,这是非常不必要的,因为我已经有一个充满数据的数据集(用于在DataGridView中显示),所以为什么要这样重新执行我在填充数据集时执行的确切SQL语句?

To help you image the context more easily, I'll post some code here: 为了帮助您更轻松地描述上下文,我将在此处发布一些代码:

DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("My SQL SELECT query", mySqlConnection);
da.Fill(ds,"myTable");

Now I want to add ds as a new DataSource for my local report, using wizard doesn't seem able to help, the new DataSource I want here can be created through the exact "My SQL SELECT query" above, that means ds is already what I want, however I don't know how to make it available for my local report's data source. 现在,我想将ds添加为本地报表的新数据源,使用向导似乎无济于事,可以通过上面确切的“我的SQL SELECT查询”创建我想要的新数据源,这意味着ds已经存在我想要什么,但是我不知道如何使它可用于本地报告的数据源。

I hope you understand my problem here, I don't want to do thing which has already been done. 希望您在这里理解我的问题,我不想做已经做的事情。

If I understood correctly... You could use an Object method that returns your datasource from your dataset not using SQL if you have the dataset in memory as a dataset. 如果我正确理解...如果内存中有数据集,则可以使用Object方法从不使用SQL的数据集中返回数据源。 You can use LINQ or the Select() method of a datatable inside your dataset to filter the data. 您可以在数据集中使用LINQ或数据表的Select()方法来过滤数据。

http://msdn.microsoft.com/en-us/library/det4aw50.aspx http://msdn.microsoft.com/zh-CN/library/det4aw50.aspx

http://msdn.microsoft.com/en-us/library/bb552415.aspx http://msdn.microsoft.com/en-us/library/bb552415.aspx

hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM