为什么我的数据库更新值未在报表查看器上显示?

时间:2014-04-01 06:03:58

标签: c# ado.net

在我的应用程序中,当我单击“提交”按钮时,所有值都将插入到数据库中。

要打印这些当前插入的值,我在其他表单上使用报告查看器。

有两个按钮提交和打印.submit按钮给我最后一个值的唯一ID和我要在报告上打印的这个id的详细信息。但是当我点击打印按钮时我不打印任何数据

我已经尝试了但是在单击打印按钮时,它不会在报表查看器上显示任何数据。 如何在点击我的打印按钮时获取当前值。我尝试了但它对当前值没有用。

           int id = Convert.ToInt32(Form1.lblbillno1);
        this.Customer_detailTableAdapter.Fill(this.DataSet1.Customer_detail,id);             
         this.Bill_DetailTableAdapter.Fill(this.DataSet2.Bill_Detail,id);
         reportViewer1.LocalReport.Refresh();
         this.reportViewer1.RefreshReport

1 个答案:

答案 0 :(得分:1)

我刚刚解决了同样的问题。我在互联网上搜索了几天,但我找不到一个好的答案。所以我希望我的帖子能帮助某人克服同样的问题。

您只需要手动定义连接,重新填充数据集并将源绑定到reportviewer。这是我的项目示例:

using Microsoft.Reporting.WinForms;


    private void ReportForm_Load(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection();
        conn.ConnectionString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\GD Robotics\VisualProjects\GDPolin\GDPolin\PolinaDB.mdf;Integrated Security=True;Connect Timeout=30";
        conn.Open();
        SqlDataAdapter reportDBTableAdapter = new SqlDataAdapter("SELECT * FROM  [ReportDB]", conn);
        DataTable polinaDBDataSet = new DataTable();
        reportDBTableAdapter.Fill(polinaDBDataSet);
        conn.Close();

        this.reportViewer1.Reset();
        this.reportViewer1.LocalReport.DataSources.Clear();
        this.reportViewer1.LocalReport.ReportPath = @"D:\GD Robotics\VisualProjects\GDPolin\GDPolin\Report1.rdlc";
        ReportDataSource rds = new ReportDataSource("DataSet1", polinaDBDataSet);//"DataSet1" is the name of your dataset. Go to .rdlc form>VIEW>Report Data>"Right click on dataset">Dataset Properties
        this.reportViewer1.LocalReport.DataSources.Add(rds);
        this.reportViewer1.RefreshReport();
    }
相关问题