Saman Zaidi

Saman Zaidi

  • NA
  • 1
  • 0

Hoe to create a crystal reoprt on the basis of user input.

May 14 2009 7:31 AM

I created a crytal report absolutely blank in my project.....

And add the following coding on the page load ()of the page:

 

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using CrystalDecisions.CrystalReports.Engine;

using CrystalDecisions.Shared;

using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page

{

private ReportDocument reportDoc;

 

protected void Page_Load(object sender, EventArgs e)

{

BindReport();

}

 

private void BindReport()

{

string id= Request.QueryString["myid"];

decimal x=Convert .ToDecimal (id );

reportDoc = new ReportDocument();

string reportPath = Server.MapPath("CrystalReport.rpt");

reportDoc.Load(reportPath);

SqlConnection conn = new SqlConnection("Data Source=01HW166928;Initial Catalog=DataStore9;Persist Security Info=True;User ID=sa;Password=Vikram@555");

 

SqlCommand cmd = new SqlCommand("SELECT * FROM [Khatauni_Masudpur] WHERE ([khatauni_no] = @Name)", conn);

cmd.Parameters.Add(new SqlParameter("@Name", System.Data.SqlDbType.Decimal ,3)).Value = x;

SqlDataAdapter daTest = new SqlDataAdapter(cmd );

DataSet dsTest = new DataSet();

conn.Open();

daTest.Fill(dsTest, "Table");

//conn.Close();

CrystalReportViewer1.Visible = true;

reportDoc.SetDataSource(dsTest); // Attach the Data source to the Report.

CrystalReportViewer1.ReportSource = reportDoc;

}

protected void Page_UnLoad(object sender, EventArgs e)

{

try

{

reportDoc.Close();

reportDoc.Dispose();

}

catch { }

}

}

 

 

 

But i m continuosly getting the error :

CrystalDecisions.CrystalReports.Engine.DataSourceException was unhandled by user code
  Message="The report has no tables."
  Source="CrystalDecisions.CrystalReports.Engine"
  StackTrace:
       at CrystalDecisions.CrystalReports.Engine.ReportDocument.SetDataSourceInternal(Object val, Type type)
       at CrystalDecisions.CrystalReports.Engine.ReportDocument.SetDataSource(DataSet dataSet)
       at _Default.BindReport() in c:\Inetpub\wwwroot\TryReport\Default.aspx.cs:line 49
       at _Default.Page_Load(Object sender, EventArgs e) in c:\Inetpub\wwwroot\TryReport\Default.aspx.cs:line 22
       at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
       at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
       at System.Web.UI.Control.OnLoad(EventArgs e)
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

 

 

Please help me as soon as possible....