Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i try creating Cristal Reports in my project but everything ok but my report cannot shoe in Cristal Reports viewer.

use dataset

my code is :
C#
protected void Page_Load(object sender, EventArgs e)
    {
        ReportDocument crystalReport = new ReportDocument();
        crystalReport.Load(Server.MapPath("~/CustomerReport.rpt"));
        Customers dsCustomers = GetData("select * from customers");
        crystalReport.SetDataSource(dsCustomers);
        CrystalReportViewer1.ReportSource = crystalReport;
        CrystalReportViewer1.RefreshReport();
        
    }

    private Customers GetData(string query)
    {
        string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
        SqlCommand cmd = new SqlCommand(query);
        using (SqlConnection con = new SqlConnection(conString))
        {
            using (SqlDataAdapter sda = new SqlDataAdapter())
            {
                cmd.Connection = con;

                sda.SelectCommand = cmd;
                using (Customers dsCustomers = new Customers())
                {
                    sda.Fill(dsCustomers, "DataTable1");
                    return dsCustomers;
                }
            }
        }
    }

<CR:CrystalReportViewer ID="CrystalReportViewer1"  runat="server" AutoDataBind="true" />
Posted
Updated 6-Jul-15 20:56pm
v2

1 solution

Hello,

Please You can Add the below link in your aspx Page and add the folder crystalreportviewer13 in Project.

Copied the crystalreportviewers13 folder from this path and add in your project and add link in your aspx Page.
C:\inetpub\wwwroot\aspnet_client\system_web\4_0_30319\crystalreportviewers13
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
        <script src="crystalreportviewers13/js/crviewer/crv.js"></script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <cr:crystalreportviewer id="CrystalReportViewer1" runat="server" autodatabind="true" xmlns:cr="#unknown" />
        </div>
        <div>
         
        </div>
    </form>
</body>
</html>
  

protected void Page_Load(object sender, EventArgs e)
    {
        ReportDocument crystalReport = new CustomerReport();
        //crystalReport.Load(Server.MapPath("~/CustomerReport.rpt"));
        Customers dsCustomers = GetData("select * from customers");
        crystalReport.SetDataSource(dsCustomers);
        CrystalReportViewer1.ReportSource = crystalReport;
        CrystalReportViewer1.DataBind();
        CrystalReportViewer1.RefreshReport();
        
    }
 
    private Customers GetData(string query)
    {
        string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
        SqlCommand cmd = new SqlCommand(query);
        using (SqlConnection con = new SqlConnection(conString))
        {
            using (SqlDataAdapter sda = new SqlDataAdapter())
            {
                cmd.Connection = con;
 
                sda.SelectCommand = cmd;
                using (Customers dsCustomers = new Customers())
                {
                    sda.Fill(dsCustomers, "DataTable1");
                    return dsCustomers;
                }
            }
        }
    }
 
Share this answer
 
Comments
Piyush Kanpariya 8-Jul-15 6:19am    
i try this but, it not work
Anil Vaghasiya 10-Jul-15 5:17am    
Hello,
have you added All References & necessary DLL releted to crystal Report such as CrystalDecisions.CrystalReports.Engine.dll, CrystalDecisions.ReportSource.dll, CrystalDecisions.Shared.dll, CrystalDecisions.Web.dll

--AV
Piyush Kanpariya 18-Jul-15 2:37am    
add all References but that is snot working
Anil Vaghasiya 20-Jul-15 1:07am    
//Just take it my example and do it

//add in Head Section

<script src="crystalreportviewers13/js/crviewer/crv.js"></script>

//add in Body
<form id="form1" runat="server">
<div>
<CR:CrystalReportViewer ID="SAPcrystalReport" runat="server" AutoDataBind="true" BestFitPage="False" HasGotoPageButton="True" HasRefreshButton="True" HasToggleGroupTreeButton="true"
HasCrystalLogo="False" ToolPanelView="None" Width="100%" ReuseParameterValuesOnRefresh="True" />
</div>
</form>

//at server side code

private void Page_Init(object sender, EventArgs e)
{
ReportDocument rd;

EmployeeReport ds = new EmployeeReport(); //EmployeeReport is Dataset name
DataTable dt = ds.Tables["empTable"];

DataRow row;

List<asiemployeedal> lstEmployee = asiEmployeeDAL.SelectAllEmployee();

foreach (var objlst in lstEmployee.Take(1000))
{
row = dt.NewRow();
row["empID"] = objlst.empID.ToString();
row["empName"] = objlst.empName;
row["address"] = objlst.address;
row["city"] = objlst.city;
row["contactNo"] = objlst.contactNo.ToString();
dt.Rows.Add(row);
}
rd = new AllEmployeeReport(); // AllEmployeeReport is RPT File
rd.SetDataSource(dt);
SAPcrystalReport.ReportSource = rd;
SAPcrystalReport.DataBind();
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900