0

I am trying to display some records to crystal report using Ado.Net dataset. When I am running my code it's showing this error. I debug my code but didn't get any exception.

Page Load

DataSet ds = new DataSet();
    DataTable dt = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {
        ReportDocument rptDoc = new ReportDocument();
        try
        {
            ds = new EmployeeDetails();
            string EmpCode = GetValues("EmpCode");
            ds = EmployeeCard(EmpCode);
            string ReportName = "EmployeeCard.rpt";
            ds.Tables[0].Merge(ds.Tables[0]);
            rptDoc.Load(Server.MapPath(ReportName));
            rptDoc.SetDataSource(ds.Tables[0]);
            CrystalReportViewer1.ReportSource = rptDoc;
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
        finally
        {
            rptDoc.Close();
            rptDoc.Dispose();
        }
    }

and Rest of the Code

private DataSet EmployeeCard(string EmpCode)
    {
        SqlCommand cmd = new SqlCommand();
        DataSet ds = null;
        try
        {
            SqlDataAdapter adp;
            string cn = Session["UserName"].ToString();
            if (Connections.Connection[Session["UserName"].ToString()].State == ConnectionState.Closed)
                Connections.Connection[Session["UserName"].ToString()].Open();
            cmd.Connection = Connections.Connection[Session["UserName"].ToString()];
            cmd.CommandText = "EmployeeMaster_pro";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("Option", "EmployeeCard".Trim());
            cmd.Parameters.AddWithValue("EmpCode", EmpCode);            
            ds = new DataSet();
            adp = new SqlDataAdapter(cmd);
            adp.Fill(ds);

            dt = ds.Tables[0];
            string value = dt.Rows[0][1].ToString();

            return ds;
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
            return ds;
        }
        finally
        {
            cmd.Parameters.Clear();
            cmd.Dispose();
            Connections.Connection[Session["UserName"].ToString()].Close();
        }
    }

    public string GetValues(string Val)
    {
        string path = HttpContext.Current.Request.Url.AbsoluteUri;
        string mainpath = path.Substring(path.IndexOf("?") + 1);
        string[] Values = mainpath.Split('&');
        for (int i = 0; i < Values.Length; i++)
        {
            string[] Data = Values[i].Split('=');
            if (Data[0].ToString() == Val)
                return Data[1].ToString();
        }
        return "";
    }

When I debug my code. I didn't get any error. Everything is working fine but CrystalReportViewer is showing this Error. I don't understand where I am doing wrong here. Please help guys....

Shaiwal Tripathi
  • 601
  • 1
  • 12
  • 32

0 Answers0