Search code examples
asp.netvisual-studio-2010c#-4.0crystal-reports

Crystal report is not showing data using Asp.net


I am using Asp.net 4.0 and Sap crystal report my problem is that I am unable to show data on to the reportViewer after binding the dataset.

Below is my Aspx designer code

<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="productRepot.aspx.cs" Inherits="ProductionPlanning1.productRepot" %>

<%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral,    PublicKeyToken=692fbea5521e1304"
Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<asp:Label ID="prdt_Label1" runat="server" Text="ProductID"></asp:Label>
<asp:TextBox ID="matrl_TextBox" runat="server"></asp:TextBox>

<asp:Button ID="rpt_Button1" runat="server" Text="PrintProduct" 
    onclick="rpt_Button1_Click"></asp:Button>
<CR:CrystalReportViewer ID="product_CrystalReportViewer1" runat="server" 
    AutoDataBind="true"></CR:CrystalReportViewer>

</asp:Content>

Product Report.aspx.cs

  protected void rpt_Button1_Click(object sender, EventArgs e)
    {
        //DataSet2 DS2 = new DataSet2();
        //Fyp_1.Product pp = new Fyp_1.Product();
        //DS2.Tables.Add(pp.GetProduct(Convert.ToInt16(matrl_TextBox.Text)).Copy());
        //DS2.Tables[0].TableName = "Product";
        //CrystalReportProduct TR = new CrystalReportProduct();
        //TR.SetDataSource(DS2);
        //product_CrystalReportViewer1.ReportSource = TR;
        //product_CrystalReportViewer1.DataBind();

        GenerateReport();




        //DataSet ds = new DataSet();
        //BookTicket_Class BT = new BookTicket_Class();
           //ds.Tables.Add(BT.GetBookTicketReport(Convert.ToInt16(TicketNO_TextBox.Text)).Copy());
        //ds.Tables[0].TableName = "BookTicket";
        //TicketReport TR = new TicketReport();
        //TR.SetDataSource(ds);
        //CrystalReportViewer1.ReportSource = TR;
        //CrystalReportViewer1.DataBind();
    }

    protected void GenerateReport()
    {
        SqlConnection sqlConn = new SqlConnection(@"Data Source=PROZECK-   PC\R2MSSQLSERVER;Initial Catalog=FYP;Integrated Security=True");

        SqlCommand comd;
        comd = new SqlCommand();
        comd.Connection = sqlConn;
        comd.CommandType = CommandType.StoredProcedure;
        comd.CommandText = "spgetproductNEW";



        comd.Parameters.Add("@MaterialID", SqlDbType.Int);
      //  int VAL = Convert.ToInt32(matrl_TextBox.Text);
        if (matrl_TextBox.Text.Trim() != "")
            comd.Parameters[0].Value = Convert.ToInt32(matrl_TextBox.Text);
        else
            comd.Parameters[0].Value = DBNull.Value;




        SqlDataAdapter sqlAdapter = new SqlDataAdapter();
        sqlAdapter.SelectCommand = comd;

        DataSet2 DS2 = new DataSet2();
        sqlAdapter.Fill(DS2, "Product");

        //oRpt.SetDataSource(ds);

        //CrystalReportViewer1.Visible = true;

        //CrystalReportViewer1.ReportSource = oRpt;
        CrystalReportProduct TR = new CrystalReportProduct();
        TR.SetDataSource(DS2);
        product_CrystalReportViewer1.ReportSource = TR;
       // product_CrystalReportViewer1.DataBind();




    }
}

Below is the screenshot of the problem is described to you .

enter image description here

But when I check the data in crystal report designer it show the data enter image description here

My FIRST code of binding the data was this then i changed it in to the above code i paste

        DataSet2 DS2 = new DataSet2();
        Fyp_1.Product pp = new Fyp_1.Product();
        DS2.Tables.Add(pp.GetProduct(Convert.ToInt16(matrl_TextBox.Text)).Copy());
        DS2.Tables[0].TableName = "Product";
        CrystalReportProduct TR = new CrystalReportProduct();
        TR.SetDataSource(DS2);
        product_CrystalReportViewer1.ReportSource = TR;
        product_CrystalReportViewer1.DataBind();

Solution

  • I think you're just missing the final call; product_CrystalReportViewer1.Refresh();