Asked by:
Am trying to load a crystal report in Crystal report viewer but with out giving a SetDataSource to ReportDocument Object

Question
-
User1594408874 posted
Hi All.
Am trying to open a Crystal report in Crystal report viewer in VS2010. I had did the earlier in VS2008( I have Shared my code below).And this code worked fine in VS208. But am trying to do the same this in VS2010 but i couldn't . And when i googled i found codes which has SetDataSource for ReportDocument Object . But where as if you see my below code which i used in VS2008 does not has to SetDataSource. I just have to pass the parameter and Load the report. and it worked fine.Please help me out to figure out the issue as my current project is running on VS2010 and i have been told not to use setdataSource.
ConnectionInfo crConnectionInfo = new ConnectionInfo();
ReportDocument cryRpt = new ReportDocument();
string ConnectionString = "Data Source = 10.3.2.190; Database = ERP_THOMAS; User ID = ***; pwd = ***";string[] connections = ConnectionString.Split(';');
crConnectionInfo.ServerName = connections[0].Substring(connections[0].LastIndexOf("=") + 1, connections[0].Length - (connections[0].LastIndexOf("=") + 1)).Trim();
crConnectionInfo.DatabaseName = connections[1].Substring(connections[1].LastIndexOf("=") + 1, connections[1].Length - (connections[1].LastIndexOf("=") + 1)).Trim();
crConnectionInfo.UserID = connections[2].Substring(connections[2].LastIndexOf("=") + 1, connections[2].Length - (connections[2].LastIndexOf("=") + 1)).Trim();
crConnectionInfo.Password = connections[3].Substring(connections[3].LastIndexOf("=") + 1, connections[3].Length - (connections[3].LastIndexOf("=") + 1)).Trim();cryRpt.Load(Server.MapPath("CrystalReport1.rpt"));
cryRpt.SetParameterValue("@id", QuotationID);
for (int i = 0; i < cryRpt.DataSourceConnections.Count; i++)
cryRpt.DataSourceConnections[i].SetConnection(crConnectionInfo.ServerName, crConnectionInfo.DatabaseName, crConnectionInfo.UserID, crConnectionInfo.Password);CrystalReportViewer1.ReportSource = cryRpt;
CrystalReportViewer1.DataBind();Thursday, January 18, 2018 9:31 AM
All replies
-
User-1838255255 posted
Hi Sugandan,
According to your description, you say can not load crystal report in VS2010, i want to know if you meet some error message? Please share them for us!
if you have crystall report installer for VS2010? if not, please check the following links:
Crystal report for visual studio 2010 is not working:
https://forums.asp.net/t/1721137.aspx?Crystal+report+for+visual+studio+2010+is+not+working
crystal report and visual studio 2010 problem:
https://www.codeproject.com/Questions/547040/crystalplusreportplusandplusvisualplusstudioplus
Best Regards,
Eric Du
Friday, January 19, 2018 6:16 AM -
User1594408874 posted
Hi Eric,
Thanks for the reply.
To put it more clear, when i try to load the Crystal report with above mentioned code only a blank page opens and it doesn't throws a error message.
And also please let me know if i can use Report Viewer control to display a crystal report .If Yes, kindly share with me how to load a crystal report in Report viewer control.
thnaks.
Sunday, January 21, 2018 5:06 AM -
User-1838255255 posted
Hi Sugandan,
Off course, you could load a crystal report in report viewer control, please check the following sample tutorial:
Beginners tutorial on how to load Crystal Reports using Crystal Report Viewer in Visual Studio 2012:
https://www.codeproject.com/Tips/695587/Beginners-tutorial-on-how-to-load-Crystal-Reports
Best Regards,
Eric Du
Friday, January 26, 2018 10:00 AM