无法在C#中将数据集分配给ReportDataSource
|
我试图将数据集作为报告的数据源传递,我希望借助winform的Form上托管的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);
}
}
关于如何将数据集分配到报表数据源的任何建议!
没有找到相关结果
已邀请:
2 个回复
粟痢凰副
糕泰灌
这对我有用。