2
Reply

Bind dataset with Crystal Report ?

Vinay  NV

Vinay NV

Aug 7 2013 12:26 PM
4.2k
Hi, I have created a dataset with 3 tables and trying to fill this dataset using dataadapter(By executing stored procedure). The data is getting filled into the dataset but it is not getting displayed in the crystal report(Getting blank report). Pls refer by code below :
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.Configuration;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
namespace CrystalEx
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string sqlCon = "Server=ServerName;Database=DBName;uid=sa;pwd=sa;connection timeout=3600;";
            SqlConnection sqlConn = new SqlConnection(sqlCon);

            SqlDataAdapter sqlAdap = new SqlDataAdapter();
//TQReportCM is a stored procedure , i am selecting a record by passing one parameter 
            sqlAdap.SelectCommand = new SqlCommand("TQReportCM", sqlConn);
            sqlConn.Open();
            DataSet1 ds = new DataSet1();

            sqlAdap.SelectCommand.CommandType = CommandType.StoredProcedure;
            sqlAdap.SelectCommand.Connection = sqlConn;
            sqlAdap.SelectCommand.Parameters.Add("@CmNo", SqlDbType.NVarChar, 400).Value = "1";
            sqlAdap.Fill(ds, ds.CM.TableName);

//TQReportCRPOCis a stored procedure , i am selecting a record by passing one parameter
            sqlAdap.SelectCommand = new SqlCommand("TQReportCRPOC", sqlConn);
            sqlAdap.SelectCommand.CommandType = CommandType.StoredProcedure;
            sqlAdap.SelectCommand.Connection = sqlConn;
            sqlAdap.SelectCommand.Parameters.Add("@Name", SqlDbType.NVarChar, 400).Value = "hello";
            sqlAdap.Fill(ds, ds.CRPOC.TableName);
//TQReportSelectHS is a stored procedure , i am selecting a record by passing one parameter


            sqlAdap.SelectCommand = new SqlCommand("TQReportSelectHS", sqlConn);
            sqlAdap.SelectCommand.CommandType = CommandType.StoredProcedure;
            sqlAdap.SelectCommand.Connection = sqlConn;
            sqlAdap.SelectCommand.Parameters.Add("@FirstName", SqlDbType.NVarChar, 400).Value = "abcd";
            
            sqlAdap.Fill(ds, ds.Customer.TableName);
            ReportDocument rptDoc = new ReportDocument();
            rptDoc.Load(Server.MapPath("CrystalReport1.rpt"));


            rptDoc.SetDataSource(ds);

            CrystalReportViewer1.DataBind();
            CrystalReportViewer1.ReportSource = rptDoc;
        }
 
    }
}

Any help would be appreciated.
Thanks in advance

Answers (2)