无法在 C# 中将数据集分配给 ReportDataSource
我正在尝试将数据集作为报告的数据源传递,我想在 winform 表单上托管的 Microsft Reporting Control 的帮助下查看该报告。我为此目的使用以下代码,但未能完成任务。
private void Form1_Load(object sender, EventArgs e)
{
// Sql Connection Object
SqlConnection con = new SqlConnection(@"Data Source=SEVEN01-PC\SQLEXPRESS;Initial Catalog=RealWorld;Integrated Security=SSPI;");
// Sql Command Object
SqlCommand cmd = new SqlCommand("Select * from ProductReorder", con);
try
{
// Open Connection
con.Open();
// Dataset Object
DataSet ds = new DataSet();
// Sql DataReader Object
SqlDataReader reader = cmd.ExecuteReader();
// Fill Data Set
ds.Tables[0].Load(reader);
// Close Sql Datareader and Connection Objects
reader.Close();
con.Close();
//provide local report information to viewer
reportViewer1.LocalReport.ReportEmbeddedResource = "ProductReorder.rptProductReorder.rdlc";
//prepare report data source
ReportDataSource rds = new ReportDataSource();
rds.Name = "dsProductReorder_dtProductReorder";
rds.Value = ds.Tables[0];
reportViewer1.LocalReport.DataSources.Add(rds);
//load report viewer
this.reportViewer1.RefreshReport();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
有关如何将数据集分配给报表数据源的任何建议!
I am trying to pass a dataset as a datasource for a report which i want to view with the help of Microsft Reporting Control hosted on a winform's Form. I am using the following code for this purpose but fails in accomplishing the task.
private void Form1_Load(object sender, EventArgs e)
{
// Sql Connection Object
SqlConnection con = new SqlConnection(@"Data Source=SEVEN01-PC\SQLEXPRESS;Initial Catalog=RealWorld;Integrated Security=SSPI;");
// Sql Command Object
SqlCommand cmd = new SqlCommand("Select * from ProductReorder", con);
try
{
// Open Connection
con.Open();
// Dataset Object
DataSet ds = new DataSet();
// Sql DataReader Object
SqlDataReader reader = cmd.ExecuteReader();
// Fill Data Set
ds.Tables[0].Load(reader);
// Close Sql Datareader and Connection Objects
reader.Close();
con.Close();
//provide local report information to viewer
reportViewer1.LocalReport.ReportEmbeddedResource = "ProductReorder.rptProductReorder.rdlc";
//prepare report data source
ReportDataSource rds = new ReportDataSource();
rds.Name = "dsProductReorder_dtProductReorder";
rds.Value = ds.Tables[0];
reportViewer1.LocalReport.DataSources.Add(rds);
//load report viewer
this.reportViewer1.RefreshReport();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Any suggestions how to assign the dataset to the report datasource!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许你可以尝试这个...
Maybe you can try this...
这对我有用。
This works for me.