在CrystalReportViewer中显示查询结果
本文关键字:查询 结果 显示 CrystalReportViewer | 更新日期: 2023-09-27 18:04:21
我在我的winform中编写了以下代码,用于在crystalReportviewer中显示my_table内容,但是没有显示:
private void Form10_Load(object sender, EventArgs e)
{
String connString = "Data Source=.''SQLEXPRESS;AttachDbFilename=|DataDirectory|''bank.mdf;Integrated Security=True;User Instance=True";
SqlConnection conn = new SqlConnection(connString);
SqlDataAdapter da = new SqlDataAdapter("SELECT * from my_table", conn);
DataTable dt = new DataTable();
da.Fill(dt);
ReportDocument rd = new ReportDocument();
rd.Load("CrystalReport2.rpt");
rd.SetDataSource(dt);
crystalReportViewer1.ReportSource = rd;
crystalReportViewer1.Show();
}
有什么问题吗?
Check that your load method is getting the full path of the report,if not then use
rd.Load(Server.MapPath("CrystalReport2.rpt")) and change your programming like i
mentioned.
private void Form10_Load(object sender, EventArgs e)
{
String connString = "Data Source=.''SQLEXPRESS;AttachDbFilename=|DataDirectory|''bank.mdf;Integrated Security=True;User Instance=True";
SqlConnection conn = new SqlConnection(connString);
SqlDataAdapter da = new SqlDataAdapter("SELECT * from my_table", conn);
DataTable dt = new DataTable();
da.Fill(dt);
ReportDocument rd = new ReportDocument();
rd.Load("CrystalReport2.rpt");
rd.SetDataSource(dt);
crystalReportViewer1.ReportSource = rd;
rd.Refresh();
this.crystalReportViewer1.ReportSource = rd;
}
I think it will help for you.