Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 带有参数的ASP.NET报表_C#_Asp.net_Reporting Services - Fatal编程技术网

C# 带有参数的ASP.NET报表

C# 带有参数的ASP.NET报表,c#,asp.net,reporting-services,C#,Asp.net,Reporting Services,我有一个名为Graph的存储过程,它应该为参数@Material获取一个值,并且我在ASP.NET中创建了一个报告,该报告应该使用存储过程中的数据显示一个图表 但是,当我尝试加载报告时,我得到: 报表处理过程中发生错误。 无法创建到数据源“PhilipsMaterialsDataSet”的连接。 ObjectDataSource“ObjectDataSource1”找不到没有参数的非泛型方法“GetData” 我尝试了不同的解决方案,但没有一个奏效。另外,我不确定是否应该在ASP代码中声明参数

我有一个名为Graph的存储过程,它应该为参数@Material获取一个值,并且我在ASP.NET中创建了一个报告,该报告应该使用存储过程中的数据显示一个图表

但是,当我尝试加载报告时,我得到:

报表处理过程中发生错误。 无法创建到数据源“PhilipsMaterialsDataSet”的连接。 ObjectDataSource“ObjectDataSource1”找不到没有参数的非泛型方法“GetData”

我尝试了不同的解决方案,但没有一个奏效。另外,我不确定是否应该在ASP代码中声明参数

顺便说一下,这里无法识别GetData,因为它有一个存储过程中的参数@Material,出于某种原因,调用它时没有任何参数

背后的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;


public partial class StatisticsPage : System.Web.UI.Page
{
    string Connectionstring = "server=(local)\\SQLEXPRESS;database=PhilipsMaterials;Integrated Security=SSPI";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

        }

    }

   protected void btndisplay_Click(object sender, EventArgs e)
    {
        BindReport();
    }
    private void BindReport()
    {
        SSRSReport report = new SSRSReport();
        SqlParameter[] sqlParams = new SqlParameter[] {
         new SqlParameter("@Material","453567068441")

      };
        string ReportDataSource = "DataSet1";
        bool bind = report.CreateReport(Connectionstring, "graph", sqlParams, ref ReportViewer1, ReportDataSource);
        if (bind)
        {
            ReportViewer1.Visible = true;
        }
    }
}


public class SSRSReport
{


       public SSRSReport()
       {
              //
              // TODO: Add constructor logic here
              //
       }
    public bool CreateReport(String Connectionstring,string StoreProcedureName ,SqlParameter[] Parameter,ref  Microsoft.Reporting.WebForms.ReportViewer ReportViewer,string ReportDataSource)
    {
        bool reportbind = false;
        using (SqlConnection con = new SqlConnection(Connectionstring))
        {

            SqlCommand com = new SqlCommand();
            com.Connection = con;
            com.CommandType = CommandType.StoredProcedure;
            com.CommandText = StoreProcedureName;
            com.Parameters.AddRange(Parameter);
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(com);
            da.Fill(ds);
            ReportDataSource datasource = new ReportDataSource(ReportDataSource, ds.Tables[0]);
            if ( ds.Tables[0].Rows.Count > 0)
            {
                ReportViewer.LocalReport.DataSources.Clear();
                ReportViewer.LocalReport.DataSources.Add(datasource);





                //This is another solution I tried:





                //List<ReportParameter> lstReportParameters = new List<ReportParameter>();
                //ReportParameter objReportParameter = new ReportParameter("Material", "453567068441");
                //lstReportParameters.Add(objReportParameter);
                //ReportViewer.LocalReport.SetParameters(lstReportParameters);
               // ReportViewer.ServerReport.Refresh();

                reportbind = true;
            }                       
        }
       return  reportbind;
    }

}
ASP代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="StatisticsPage.aspx.cs" Inherits="StatisticsPage" %>

<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Test SSRS</title>
</head>
<body>
      <form id="form1" runat="server">
    <div>

    </div>
        <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" Height="610px" Width="1179px" ShowParameterPrompts="true">
            <LocalReport ReportPath="Report.rdlc" >
                <DataSources>
                    <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet1" />
                </DataSources>
            </LocalReport>
        </rsweb:ReportViewer>
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData" TypeName="PhilipsMaterialsDataSetTableAdapters.GraphTableAdapter" >
        </asp:ObjectDataSource>
          <asp:ScriptManager ID="ScriptManager1" runat="server">
          </asp:ScriptManager>
    </form>
</body>
</html>

错误是GetData需要一些参数,您必须通过添加如下参数来提供这些参数:

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData" TypeName="PhilipsMaterialsDataSetTableAdapters.GraphTableAdapter" >
   <SelectParameters>
        <asp:Parameter Name="X" DefaultValue="Y" .. />
   </SelectParameters>
</asp:ObjectDataSource>

与其发布页面类代码,不如发布GetData方法?非常感谢,现在可以加载报告了,但是我得到:没有可用数据我添加了:OK。必须通过添加DefaultValue来提供值。您可以将代码中的默认值设置为所需的值。默认值是提供给函数的值。或者看看其他参数,如ControlParameter、SessionParameter,它们比默认值具有更多功能。