0

i am trying to create and fill crystal report via code but an error occurred, REPORT HAS NO TABLES but when i try to extract data from DATASET then it shows exact data,no problem but doesn't work for Crystal report.

CODE:

protected void Dataset_load() 
    {
        SqlConnection sqlcon = new SqlConnection(conStr);
        SqlCommand sqlCom = new SqlCommand("select * from Login", sqlcon);
        SqlDataAdapter sqlDA = new SqlDataAdapter(sqlCom);
        DataSet ds = new DataSet("CRDataSet");

        try
        {
            sqlcon.Open();
            //sqlCom.ExecuteNonQuery();
            sqlDA.Fill(ds,"Login");

            ReportDocument rd = new ReportDocument();
            rd.Load(Server.MapPath("CrystalReport.rpt").ToString());
            rd.SetDataSource(ds.Tables["Login"]);
            CrystalReportViewer1.ReportSource = rd;


        }
        catch (Exception exc)
        {
            Response.Write(exc.Message);
        }
        finally 
        {
            sqlcon.Close();
        }
1
Contributor
1
Reply
11
Views
4 Years
Discussion Span
Last Post by HunainHafeez
0

done

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Security;
using System.Web.Configuration;
using CrystalDecisions.CrystalReports.Engine;

public partial class crystalReport_manual : System.Web.UI.Page
{
    String conStr = WebConfigurationManager.ConnectionStrings["LoginDatabaseConnectionString"].ConnectionString;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack) 
        {
            Dataset_load();
        }
    }

    protected void Dataset_load() 
    {
        SqlConnection sqlcon = new SqlConnection(conStr);
        SqlCommand sqlCom = new SqlCommand("select * from Login", sqlcon);
        SqlDataAdapter sqlDA = new SqlDataAdapter(sqlCom);
       // DataSet ds = new DataSet("CRDataSet");

        try
        {
            sqlcon.Open();
            //sqlCom.ExecuteNonQuery();
            //sqlDA.Fill(ds,"Login");

            DataSet1 ds = new DataSet1();
            DataTable dt = new DataTable("DT_CR");
            sqlDA.Fill(dt);
            ds.Tables[0].Merge(dt);

            ReportDocument rd = new ReportDocument();
            rd.Load(Server.MapPath("CrystalReport.rpt"));
            rd.SetDataSource(ds);
            CrystalReportViewer1.ReportSource = rd;


        }
        catch (Exception exc)
        {
            Response.Write(exc.Message);
        }
        finally 
        {
            sqlcon.Close();
        }

        //foreach (DataRow dr in ds.Tables["Login"].Rows) 
        //{
        //    //ListItem li = new ListItem();
        //    Response.Write(dr["name"] + "--------------" + dr["email"] + "--------------" + dr["pwd"]+ "<br/>");
        //    //li.Value = dr["stid"].ToString();
        //}
    }

    protected void reportLoad() 
    {

    }
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.