0

当我从页面的下拉列表中选择销售人员时,我想在管理面板中显示报告,但没有显示任何内容并在此处显示一些错误。

下面是我的代码:

protected void BtnViewReport_Click(object sender, EventArgs e)
{
    ReportViewer1.ProcessingMode = ProcessingMode.Local;
    ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/SalesPerson.rdlc");
    DataSet ds = GetData("select * from customer_new where salesperson in (select +
    email from Registration where name='" + ddsalesperson.SelectedValue.ToString() + 
    "')");
    ReportDataSource datasource = new ReportDataSource("customer_new",ds.Tables[0]);
    ReportViewer1.LocalReport.DataSources.Clear();
    ReportViewer1.LocalReport.DataSources.Add(datasource);
}
private DataSet GetData(string query)
{
    string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    SqlCommand cmd = new SqlCommand(query);
    using (SqlConnection con = new SqlConnection(conString))
    {
        using (SqlDataAdapter sda = new SqlDataAdapter())
        {
            cmd.Connection = con;
            sda.SelectCommand = cmd;
            using (DataSet ds = new DataSet())
           {
                  sda.Fill(ds, "customer_new");
                  return ds;
            }
        }
    }
}

我收到以下错误:

尚未为数据源“DataSet1”提供数据源实例。

4

1 回答 1

0

该错误意味着数据集“DataSet1”尚未收到数据。我猜测数据集“customer_new”实际上并不存在,或者如果确实存在,您有 2 个数据集,其中一个您可能正在使用,也可能不使用。尝试:

ReportDataSource datasource = new ReportDataSource("DataSet1",ds.Tables[0]);
于 2013-10-18T14:29:44.357 回答