using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Data;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;



namespace test
{
    public partial class WebForm1 : System.Web.UI.Page
    {

        string username;
        string fname;

        protected void submit_Click(object sender, EventArgs e)
        {
            username = nametxtbox.Text;
            fname = fnametxtbox.Text;

            CrystalReport1 report = new CrystalReport1();

            using (SqlConnection con = DALHelper.GetConnection())
            {

                SqlCommand cmd = new SqlCommand("testsproc", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@username",username);
                cmd.Parameters.AddWithValue("@fname", fname);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataSet1 ds = new DataSet1();
                da.Fill(ds, "users");

                CrystalReportViewer1.Visible = true;

                report.SetDataSource(ds.Tables["users"]);

                CrystalReportViewer1.ReportSource = report;
                CrystalReportViewer1.RefreshReport();


                try
                {
                    con.Open();
                    int count = cmd.ExecuteNonQuery();

                }
                catch
                {
                    throw;

                }

                finally
                {
                    if (con != null)
                    {
                        con.Close();
                        con.Dispose();

                    }
                    cmd.Dispose();
                }


            }
        }
    }
}




************Webform*********

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="test.WebForm1" %>

<%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
    Namespace="CrystalDecisions.Web" TagPrefix="CR" %>

<!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 runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    Name    <asp:TextBox id="nametxtbox" runat="server"></asp:TextBox>
    <br />
    <br />
    Father Name    <asp:TextBox id="fnametxtbox" runat="server"></asp:TextBox>
    <br />
    <br />
    <asp:Button ID="submit" runat="server" Text="Submit" onclick="submit_Click" />
    </div>
    </form>
    <div>

        <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" 
            AutoDataBind="false" Height="1039px" ReportSourceID="CrystalReportSource1" 
            Width="901px"  />
        <CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
            <Report FileName="CrystalReport1.rpt">
            </Report>
        </CR:CrystalReportSource>    
    </div>
</body>
</html>

*********** Please help its my job requirement and i am unable to sort out problem plz plz************

Dani AI

Generated

Short diagnosis (based on 's posts): the code mixes two binding approaches and runs the stored procedure twice. The CrystalReportViewer in the page is tied to a CrystalReportSource control (ReportSourceID), while the code also sets the viewer.ReportSource at runtime — this can silently prevent the runtime-assigned ReportDocument from being used. Also, calling ExecuteNonQuery after using a DataAdapter.Fill is unnecessary (and can be incorrect for a stored-proc that returns rows). There is no check for an empty result set and the ReportDocument is not being closed/disposed, which commonly causes temp-file buildup.

Recommended, minimal checklist to fix the problem

  • Choose one approach: either let the report pull data itself (use CrystalReportSource/Report parameters) or push a DataSet/DataTable into a ReportDocument and assign that to the viewer. Do not mix both.
  • If pushing data: remove the CrystalReportSource control / ReportSourceID from the viewer markup and set the viewer.ReportSource in code.
  • Use DataAdapter.Fill(...) and then confirm results exist (Tables.Count and Rows.Count) before binding. Do not call ExecuteNonQuery when expecting result rows.
  • Always close and dispose the ReportDocument after use (for example in Page_Unload or finally block) to free temp files.

Minimal push-binding pattern (illustrative)

var rpt = new ReportDocument();
rpt.Load(Server.MapPath("~/Reports/YourReport.rpt"));
if (myDs.Tables.Count>0 && myDs.Tables[0].Rows.Count>0) {
  rpt.SetDataSource(myDs);
  CrystalReportViewer1.ReportSource = rpt;
  CrystalReportViewer1.RefreshReport();
}
// later: rpt.Close(); rpt.Dispose();

Extra troubleshooting notes

  • Ensure the report layout was designed against the same schema as the DataSet being passed (typed XSD helps).
  • On deployment, confirm the Crystal runtime installed matches the app bitness; enable 32-bit in the IIS app pool if needed.
  • Replace empty catch blocks with logging so real exceptions can be seen. These steps address the most common causes for the behavior described in the thread.

no one have idea

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.