Asp net C#网页RDLC报告未显示数据

时间:2017-03-13 11:39:14

标签: c# asp.net report webpage rdlc

我是C#和Asp.net的新手,我正在尝试使用Rdlc报告,但我无法在报告上打印数据

<body>
    <form id="form1" runat="server">
    <div>


        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

        <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" >
            <LocalReport ReportPath="Report.rdlc">

            </LocalReport>

        </rsweb:ReportViewer>

        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

         <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
    </div>

    </form>
</body>




 protected void Page_Load(object sender, EventArgs e)
{   
    if (!IsPostBack)
    {
        string before = Session["before"].ToString();
        string after = Session["after"].ToString();

        Label1.Text = before.ToString();
        Label2.Text = after.ToString();

        string src = "Data Source=.; Initial Catalog=mydbtry; Integrated Security=true;";
        SqlConnection con = new SqlConnection(src);
        try
        {
            con.Open();

            DateTime b = Convert.ToDateTime(before);
            DateTime a = Convert.ToDateTime(after);
            string query = "Select * from firstTable where id = 155";
             SqlCommand cmd = new SqlCommand(query);
            DataSet ds;
            using (con)
            {
                using (SqlDataAdapter da = new SqlDataAdapter())
                {
                    cmd.Connection = con;
                    da.SelectCommand = cmd;
                    ds = new DataSet();
                    da.Fill(ds);

                }
            }

            ReportViewer1.ProcessingMode = ProcessingMode.Local;
            ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc");
            ReportDataSource rds = new ReportDataSource("DataSet1", ds.Tables[0]);
            ReportViewer1.LocalReport.DataSources.Clear();
            ReportViewer1.LocalReport.DataSources.Add(rds);
            ReportViewer1.LocalReport.Refresh();                
        }


        catch (Exception ex)
        {


        }


    }
  
    

我现在面临的问题是,我的表是空的,数据没有填充。     我正在使用sql server 2012,我已经检查了正常工作的连接。

         

执行后

  

enter image description here

  
    

的数据集

  

enter image description here

  
    

Report.RDLC

  

enter image description here

任何帮助都将受到高度赞赏。

1 个答案:

答案 0 :(得分:1)

尝试通过 ObjectDataSource 控件填充报告。它自动工作,不需要输入任何代码