How to display Crystal Report via C# code? [Resolved]

Posted by Laghaterohan under Regular Expressions on 9/21/2010 | Points: 10 | Views : 29313 | Status : [Member] | Replies : 2

I have prepared a crystal report ( 3.5 / vs 2008) .

On my web form i have a textbox which accepts a membership number and a View button. When i enter the membership number and click on view my report should be displayed below on the same page with the appropriate details of that member. I have prepares SP for the same.

Below is the code that am trying , I want to know how to proceed further...
ReportDocument RPT = new ReportDocument();
RPT.Load(Server.MapPath(// path here)); // Here i am getting error Virtual Path Invalid....
this.CrystalReportViewer1.ReportSource = RPT;

My Crystal report name is SampleReport.rpt.

Also please let me know the namespace that we need to use..

i searched enuf for the code that can help me out but in vain..

Please help me to solve this problem...

Thanks in advance..

Rohan Laghate

Best Regards,
Rohan Laghate


Posted by: Laghaterohan on: 9/21/2010 [Member] Starter | Points: 50


I have solved the above problem by doing following :

ReportDocument objReport = new ReportDocument();

CrystalReportViewer1.ReportSource = @" "; // Report Path
objReport.Load(@" "); // Report Path
ParameterField f1 = CrystalReportViewer1.ParameterFieldInfo[0];
ParameterDiscreteValue v1 = new ParameterDiscreteValue();
v1.Value = Convert.ToInt32(txtNo.Text); // input field
CrystalReportViewer1.Visible = true;
_CreateConnection(); // This method contains my connection

Finally its working!!

Best Regards,
Rohan Laghate

Laghaterohan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Amritha444 on: 9/21/2010 [Member] Starter | Points: 25

This to findout records with customerId greater than textbox value

protected void Button1_Click(object sender, EventArgs e)
string condition = "{Customers.CustomerId}>" + TextBox1.Text;
CrystalReportViewer1.SelectionFormula = condition;
CrystalReportViewer1.ReportSource = Server.MapPath("CrystalReport.rpt");

Laghaterohan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response