简体   繁体   English

如何在报表查看器中的表中显示数据

[英]How to show data in a table in report viewer

I want to get data from sql server (with custom query and connection string) and use tha data to fill a table in report viewer 我想从SQL Server(带有自定义查询和连接字符串)获取数据,并使用Tha数据填充报表查看器中的表

here is my code to fill a DataGridView, I want something like this: 这是我的代码来填充DataGridView,我想要这样的东西:

MyDB db = new MyDB();//class that contains my sql connection
string sql = "SELECT * FROM factoritem WHERE fid='{0}'";
sql = string.Format(sql, _fid);//_fid is a identity that it's value has been set before
SqlDataAdapter sda = new SqlDataAdapter(sql, db.MyConn);
DataSet ds = new DataSet();
BindingSource bs = new BindingSource();
sda.Fill(ds);
bs.DataSource = ds.Tables[0].DefaultView;
DGV_FactorItem.DataSource = bs;

First Create an DataSet file(.XSD). 首先创建一个数据集文件(.XSD)。 Then create DataTable(dt) with fields the same as bs and the assign bs with dt . 然后使用与bs相同的字段创建DataTable(dt),并使用dt分配bs。 after that dt appears in DataSource of your Report you can select any fields of that. 在您的报告的数据源中显示该dt之后,您可以选择该字段的任何字段。 maybe this link can help you http://www.mindstick.com/Articles/13169999-ef3b-496c-b502-caef973c3bb2/?Using%20ReportViewer%20in%20WinForms%20C 也许此链接可以为您提供帮助http://www.mindstick.com/Articles/13169999-ef3b-496c-b502-caef973c3bb2/?使用% 20ReportViewer%20in%20WinForms% 20C

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

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