一种数据源实例尚未提供为数据源“请求”(A data source instance has not

2019-08-19 04:56发布

我得到我的ReportViewer这我不知道如何纠正这种错误....我是gettings的错误是:“一个数据源实例尚未为数据源‘请求’提供。” 我试图寻找这一点,但无法找到任何东西,我可以看到这是错误的,可有人请点我在正确的方向? 这是我的reportvierer的样子:

    <rsweb:ReportViewer ID="rptViewer" runat="server" Height="654px" 
Width="924px" Font-Names="Verdana" Font-Size="8pt" 
    InteractiveDeviceInfos="(Collection)" WaitMessageFont-Names="Verdana" 
    WaitMessageFont-Size="14pt">
    <LocalReport ReportPath="Report.rdlc">
    </LocalReport>

这是我使用中的ReportViewer的代码:

    SqlConnection conn;

protected void Page_Load(object sender, EventArgs e)
{
    conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

    conn.Open();

    if (!Page.IsPostBack)
    {
        runRptViewer();
    } 

}
    private DataTable getData()
{
    DataSet dss = new DataSet();
    string sql = "";
    sql = "SELECT CC_Request.Company, CC_Request.Attention, CC_Request.Telephone, CC_Request.Email, CC_Items.Model, CC_Items.SerialNo, CC_ItemsRequested.Item, CC_ItemsRequested.Quantity, CC_ItemsRequested.Price, CC_ItemsRequested.ModelID, CC_Items.RequestID FROM CC_Request INNER JOIN CC_Items ON CC_Request.RequestID = CC_Items.RequestID INNER JOIN CC_ItemsRequested ON CC_Items.ModelID = CC_ItemsRequested.ModelID WHERE (CC_Request.Company = 'Alpha') AND (CC_ItemsRequested.ModelID = 20) AND (CC_Items.RequestID = 1)";
    SqlDataAdapter da = new SqlDataAdapter(sql, conn);
    da.Fill(dss);
    DataTable dt = dss.Tables[0];
    return dt;
}

private void runRptViewer()
{
    this.rptViewer.Reset();
    this.rptViewer.LocalReport.ReportPath = Server.MapPath("Reports\\Report.rdlc");
    ReportDataSource rds = new ReportDataSource("dsNewDataSet_Table", getData());
    this.rptViewer.LocalReport.DataSources.Clear();
    this.rptViewer.LocalReport.DataSources.Add(rds);
    this.rptViewer.DataBind();
    this.rptViewer.LocalReport.Refresh();
}

任何帮助将不胜感激。

编辑 - - - - - - - - - - - -

这并不工作之一:

    private DataTable getData()
{
    DataTable dtable = new DataTable();
    dtable.TableName = "dtNewDataSet_Table";
    string sql = "";
    sql = "SELECT CC_Request.Company, CC_Request.Attention, CC_Request.Telephone, CC_Request.Email, CC_Items.Model, CC_Items.SerialNo, CC_ItemsRequested.Item, CC_ItemsRequested.Quantity, CC_ItemsRequested.Price, CC_ItemsRequested.ModelID, CC_Items.RequestID FROM CC_Request INNER JOIN CC_Items ON CC_Request.RequestID = CC_Items.RequestID INNER JOIN CC_ItemsRequested ON CC_Items.ModelID = CC_ItemsRequested.ModelID WHERE (CC_Request.Company = 'Alpha') AND (CC_ItemsRequested.ModelID = 20) AND (CC_Items.RequestID = 1)";
    SqlDataAdapter da = new SqlDataAdapter(sql, conn);
    da.Fill(dtable);
    DataTable dt = dtable;
    return dt;
}

Answer 1:

我也面临这个问题,这就是为什么我来到这里。

我想不通的问题,我张贴在这里,以帮助一些一谁得到这类型的问题。

  1. RDLC的我的数据来源是“dsClientPayList”
  2. 我将数据源在身后像我的代码:

     ReportViewer1.LocalReport.DataSources.Clear(); ReportDataSource rd = new ReportDataSource("dsData1", DAL.MyDBModel.snData().Tables[0]); ReportViewer1.LocalReport.DataSources.Add(rd); 

它被扔同样的错误。

解:

在我后面的代码,我从“dsData1”“dsClientPayList”(同RDLC)改变ReportDataSource的参数。

ReportDataSource rd = new ReportDataSource("dsClientPayList", DAL.MyDBModel.snData().Tables[0]);

它的工作原理

结论: 数据源名称必须在两个RDLC和的ReportViewer一样。

由于编码愉快:)



Answer 2:

你必须将所有使用该报告中的数据源。

在这种情况下,如果只有一个数据源,应该是这样的

ReportDataSource rds = new ReportDataSource("Request", getData());


Answer 3:

我宁愿用“使用”的声明为正确的对象处理和错误处理做

using (SqlConnection conn = new SqlConnection(connStr)) {
using(SqlCommand comm = new SqlCommand()) {
comm.Connection = conn;
comm.CommandText = sql;

...

try {
conn.Open();
comm.ExecuteNonQuery();
}
catch(SqlException e) {
// in case something is wrong
}
}
}


文章来源: A data source instance has not been supplied for the data source 'Request'