Hi all,
I need help in generating a crystal report. what i have done in my project is, I have bound the data from sql database in a datagridview. Now on double click of the particular record, it should display a crystal report having respective records. And later i need to export this rpt file or crystal report to pdf. How is it possible to do?
I am doing it in c#.net.
hoping for help
Thanks.
Loading
Suthish NairPosted Oct 8, 2010, 3:26 AM
karthick kumarPosted Oct 8, 2010, 2:55 AM
Dont Bother about 'ID'.Because here itSelf you are getting Dataset using Select Command .The Id Is for Passing Parameter to the stord procedure.
You Should use an DataSet File (.Xsd) File.Bind ur Select Command dataset value to that xsd file. Make Xml Connection to the crystal report .Use the xsd file in the crystal report.
CrystalDecisions.CrystalReports.Engine.ReportDocument rpt =
new CrystalDecisions.CrystalReports.Engine.ReportDocument();
string server = "ServerName";//Provide your server name
string database = "database";//Provide your database name
string userid = "userid";////Provide your userid
string password = "password"//Provide your password
rpt.Load("//TestReport.rpt");//Provide path of the report
for (int i = 0; i < rpt.DataSourceConnections.Count; i++)
rpt.DataSourceConnections[i].SetConnection(server, database, userid, password);
rpt.SetDataSource(dataset);//Use Your Dataset Vaue here.
rpt.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat,
HttpContext.Current.Response, true, "TestReport");
Ruchi RPosted Oct 7, 2010, 2:34 AM
but in cell id which id should i pass and i am not using stored procedure. I am accessing data from sql command. so how should i do it.
karthick kumarPosted Oct 6, 2010, 6:51 AM
First of all add refrence of crystal report engine to ur application .
On doublicking the datagridview i think the row is selected.
On double clicking event try this code:
CrystalDecisions.CrystalReports.Engine.ReportDocument rpt =
new CrystalDecisions.CrystalReports.Engine.ReportDocument();
string server = "ServerName";//Provide your server name
string database = "database";//Provide your database name
string userid = "userid";////Provide your userid
string password = "password"//Provide your password
rpt.Load("//TestReport.rpt");//Provide path of the report
for (int i = 0; i < rpt.DataSourceConnections.Count; i++)
rpt.DataSourceConnections[i].SetConnection(server, database, userid, password);
string Value = datagridview.SelectedRow.Cells["ID"].Value.ToString();//Provide Datagridview Selected Row cell value ie.master value for the crystal reports data from datagridview//
rpt.SetParameterValue(0, Convert.ToInt32(Value));//The parameter count should match the stored procedure parameter
rpt.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat,
HttpContext.Current.Response, true, "TestReport");
--If my answer help u in anyway.mark it is answered.