Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
hi,
i am developing a small ASP.net application which also uses crystal report to also generate some report onLoad event and also when parameters are specified. the application works all right but the crystal report does not load neither does it return any exception. some times the page takes too long load and with that situation the portion suppose to show the crystal report displays an error (error - Logon Failed ). below is my code for generating the crystal report. Please help. Thank you Nana.

C#
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports;
using CrystalDecisions.Shared;
using CrystalDecisions.Web;

namespace WebApplication1.Reports
{
    public partial class rptLoanApp : System.Web.UI.Page
    {
        SqlConnection con = new SqlConnection(@"Data Source=BISTASOLU\BISTASOL;MultipleActiveResultSets = true;Initial Catalog=HeartLand;Integrated Security=True");

        DataSet dst = new DataSet();
        SqlDataAdapter dat = null;
        SqlCommand comm = new SqlCommand();

        protected void Page_Load(object sender, EventArgs e)
        {
            comm.CommandText = "SELECT * FROM vwLoanApp";
            comm.CommandType = CommandType.Text;
            comm.Connection = con;
            comm.Connection.Open();

            dat = new SqlDataAdapter();
            dat.SelectCommand = comm;
            dat.Fill(dst, "vwLoanApp");

            crptAppLoans app = new crptAppLoans();
            app.Load(Server.MapPath("~/Reports/crptAppLoans.rpt"));
            app.SetDataSource(dst);

            CrystalReportViewer1.ReportSource = app;
            CrystalReportViewer1.DataBind();
           
            comm.Connection.Close();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            if (CheckBox1.Checked == true)
            {
                DateTime Datefrom = Convert.ToDateTime(txtDateFrm.Text);
                DateTime Dateto = Convert.ToDateTime(txtDateTo.Text);                

                comm.CommandText = "SELECT * FROM vwLoanApp WHERE APP_DATE > '"+ Datefrom +"'AND APP_DATE < '"+ Dateto +"' ";
                comm.CommandType = CommandType.Text;
                comm.Connection = con;
                comm.Connection.Open();

                dat = new SqlDataAdapter();
                dat.SelectCommand = comm;
                dat.Fill(dst, "vwLoanApp");

                crptAppLoans app = new crptAppLoans();
                app.Load(Server.MapPath("~/Reports/crptAppLoans.rpt"));
                app.SetDataSource(dst);
                
                CrystalReportViewer1.ReportSource = app;
                CrystalReportViewer1.DataBind();
               

                comm.Connection.Close();
            }
            else
            {
                if (txtReq.Text != "" && txtCustID.Text == "")
                {
                    string reqID = txtReq.Text;
                    
                    comm.CommandText = "SELECT * FROM vwLoanApp WHERE REQUEST_ID = '" + reqID + "'";
                    comm.CommandType = CommandType.Text;
                    comm.Connection = con;
                    comm.Connection.Open();

                    dat = new SqlDataAdapter();
                    dat.SelectCommand = comm;
                    dat.Fill(dst, "vwLoanApp");

                    crptAppLoans app = new crptAppLoans();
                    app.Load(Server.MapPath("~/Reports/crptAppLoans.rpt"));
                    app.SetDataSource(dst);

                    CrystalReportViewer1.ReportSource = app;
                    CrystalReportViewer1.DataBind();
                }
                else if (txtReq.Text != "" && txtCustID.Text != "")
                {
                    string reqID = txtReq.Text;
                    int custID = Convert.ToInt32(txtCustID.Text);

                    comm.CommandText = "SELECT * FROM vwLoanApp WHERE REQUEST_ID = '" + reqID + "' AND CUST_ID = '"+ custID +"'";
                    comm.CommandType = CommandType.Text;
                    comm.Connection = con;
                    comm.Connection.Open();

                    dat = new SqlDataAdapter();
                    dat.SelectCommand = comm;
                    dat.Fill(dst, "vwLoanApp");

                    crptAppLoans app = new crptAppLoans();
                    app.Load(Server.MapPath("~/Reports/crptAppLoans.rpt"));
                    app.SetDataSource(dst);

                    CrystalReportViewer1.ReportSource = app;
                    CrystalReportViewer1.DataBind();

                    comm.Connection.Close();
                }
                else
                {
                    Label1.Text = "PLEASE PROVIDE SEARCH PARAMETER";
                }
            }
        }
    }
}
Posted
Updated 24-May-13 2:55am
v3
Comments
Sunasara Imdadhusen 24-May-13 5:52am    
Have you checked your query will return any records?
Nana Brown 24-May-13 6:08am    
Yes Sunasara it returns the records i want to see on the report
[no name] 24-May-13 8:01am    
"crystal report displays an error", don't you suppose that telling us which error it is, instead of making us guess, would be helpful information?
Nana Brown 24-May-13 8:56am    
sorry i omitted that - Logon Failed

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