I am new to crystal report so please help me with my problem.
I did created one crystal report and in my web page i do have report viewer but my problem is i can not bind it directly to any database object because i am using active directory and database both. so i am having one datatable in my codebehind where i am
getting all information needed to create any report.
i dont know how to bind my code behind's datatable to crystal report and where i have to do that?
Thanks for your reply but i can not create dataset,
I am getting all personid and their username(Their Company's Email address) and thn i am serching for them in active directory and getting all their information in one datatable then if any information is required for them from database then i am getting
that also in data table.
and finally i am using that datatable so i can not create any dataset and then datatable from database fields.
You just need to create new dataset at runtime and add your DataTable to the dataset before calling SetDataSource method of ReportDocument.
e.g.
ReportDocument rptDoc = new ReportDocument();
rptDoc.Load(Server.MapPath("../Reports/SimpleReports.rpt"));
DataSet ds = new DataSet();
ds.Tables.Add(datatable); // datatable is your populated datatable.
//set dataset to the report viewer.
rptDoc.SetDataSource(ds);
CrystalReportViewer1.ReportSource = rptDoc;
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: CrystalDecisions.CrystalReports.Engine.DataSourceException: The report has no tables.
Source Error:
I am getting this error when i did try to run that code.
when
i did check this ds there is datatabel in it and 3 rows are there in it but i am not getting whats the problem with it.
Line 67:
Line 68: //set dataset to the report viewer.
Line 69: rptDoc.SetDataSource(ds); Line 70: CrystalReportViewer1.ReportSource = rptDoc;
Line 71:
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 ViewExistingProfile.Page_Load(Object sender, EventArgs e) in c:\WebWorking\TrainingAppNewDB\ViewExistingProfile.aspx.cs:line 70
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)
InnerException:
neha24
Member
39 Points
74 Posts
How to bind datatable to crystal report?
Apr 18, 2012 01:25 PM|LINK
Hello all,
I am new to crystal report so please help me with my problem.
I did created one crystal report and in my web page i do have report viewer but my problem is i can not bind it directly to any database object because i am using active directory and database both. so i am having one datatable in my codebehind where i am getting all information needed to create any report.
i dont know how to bind my code behind's datatable to crystal report and where i have to do that?
Can you please help me with this?
avinash_bhud...
Contributor
2881 Points
517 Posts
Re: How to bind datatable to crystal report?
Apr 18, 2012 01:34 PM|LINK
You need to use ReportDocument's "SetDataSource" method to bind DataTable to crystal report.
Refer the link
http://www.codeproject.com/Articles/166291/Generate-a-report-using-Crystal-Reports-in-Visual
neha24
Member
39 Points
74 Posts
Re: How to bind datatable to crystal report?
Apr 18, 2012 01:46 PM|LINK
Thanks for your reply but i can not create dataset,
I am getting all personid and their username(Their Company's Email address) and thn i am serching for them in active directory and getting all their information in one datatable then if any information is required for them from database then i am getting that also in data table.
and finally i am using that datatable so i can not create any dataset and then datatable from database fields.
Please help me if you know something about this
avinash_bhud...
Contributor
2881 Points
517 Posts
Re: How to bind datatable to crystal report?
Apr 18, 2012 01:56 PM|LINK
You just need to create new dataset at runtime and add your DataTable to the dataset before calling SetDataSource method of ReportDocument.
e.g.
ReportDocument rptDoc = new ReportDocument(); rptDoc.Load(Server.MapPath("../Reports/SimpleReports.rpt")); DataSet ds = new DataSet(); ds.Tables.Add(datatable); // datatable is your populated datatable. //set dataset to the report viewer. rptDoc.SetDataSource(ds); CrystalReportViewer1.ReportSource = rptDoc;Hope it helps.
neha24
Member
39 Points
74 Posts
Re: How to bind datatable to crystal report?
Apr 18, 2012 02:19 PM|LINK
thanks for your reply,
The report has no tables.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: CrystalDecisions.CrystalReports.Engine.DataSourceException: The report has no tables.
Source Error:
I am getting this error when i did try to run that code.
when i did check this ds there is datatabel in it and 3 rows are there in it but i am not getting whats the problem with it.
Line 67: Line 68: //set dataset to the report viewer. Line 69: rptDoc.SetDataSource(ds); Line 70: CrystalReportViewer1.ReportSource = rptDoc; Line 71:can you please help me?
neha24
Member
39 Points
74 Posts
Re: How to bind datatable to crystal report?
Apr 18, 2012 02:46 PM|LINK
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 ViewExistingProfile.Page_Load(Object sender, EventArgs e) in c:\WebWorking\TrainingAppNewDB\ViewExistingProfile.aspx.cs:line 70
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)
InnerException:
neha24
Member
39 Points
74 Posts
Re: How to bind datatable to crystal report?
Apr 18, 2012 07:50 PM|LINK
Do i have to do anything in crystal report?? i just created crystal report nothing is in it so do i have to do anything thr?
avinash_bhud...
Contributor
2881 Points
517 Posts
Re: How to bind datatable to crystal report?
Apr 19, 2012 01:52 PM|LINK
You can refer these links to get more idea on how to create crystal reports.
http://www.dotnetking.com/ArticleDetails.aspx?ArticleID=44
http://www.codeproject.com/Articles/142064/Step-by-Step-Creation-of-Crystal-Report-using-its
http://www.aspfree.com/c/a/ASP.NET/Programming-Crystal-Reports-with-ASP-NET-2-0/
http://www.codeproject.com/Articles/20670/Dynamic-Crystal-Report-with-C
http://www.c-sharpcorner.com/UploadFile/rsubhajit/CrystalReportwithDataSet03012006060655AM/CrystalReportwithDataSet.aspx