我完成了我的按钮并以单一形式报告查看器。但是,我的报告没有显示,也没有数据。
private void btnGenerate_Click(object sender, EventArgs e)
{
string connectionstring = "MultipleActiveResultSets=True;Data Source=ECSTSRD;Initial Catalog=SSWSQL;User ID=sswuser;Password=sswuser123";
SqlConnection myconnection = new SqlConnection(connectionstring);
myconnection.Open();
string sql = "SELECT customer, imp_license_no, psq_level FROM customer WHERE customer= @cust1";
SqlCommand custcom = new SqlCommand(sql, myconnection);
custcom.Parameters.AddWithValue("@cust1", cboFrom.SelectedValue.ToString());
SqlDataAdapter da = new SqlDataAdapter(custcom);
DataSet1 ds = new DataSet1();
da.Fill(ds, "customer");
cboFrom.DataSource = ds.Tables["customer"];
cboFrom.DisplayMember = "customer";
cboFrom.ValueMember = "customer";
myconnection.Close();
LocalReport report = new LocalReport();
reportViewer1.Reset();
reportViewer1.LocalReport.ReportPath = "Report1.rdlc";
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", customerBindingSource));
reportViewer1.LocalReport.Refresh();
}
答案 0 :(得分:1)
reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", customerBindingSource));
我的代码中没有customerBindingSource
。它可能应该引用数据表ds.Tables["customer"]
。
答案 1 :(得分:0)
1-reportViewer1.Reset();
2-reportViewer1.LocalReport.DataSources.Clear();
3-reportViewer1.LocalReport.ReportPath = "Report1.rdlc";
4-reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", customerBindingSource));
5-reportViewer1.LocalReport.Refresh();
6- reportViewer1.RefreshReport();
你应该确定rdlc文件中的设计就像数据集设计