0

我在我的 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();
        }

问题是什么?

4

1 回答 1

0
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.
于 2013-03-18T10:23:53.863 回答