Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

how to pass parameters to crystal reports / .rdlc reports using asp.net | Passing Parameters from ASP.NET Application to Crystal Report using asp.net

Nov 17, 2011
Introduction:

In this article I will explain how to pass parameters to crystal reports using asp.net.


Description:

In Previous post I explained clearly about how to create crystal report using asp.net. Now I will explain how to load crystal reports based on parameters using asp.net. This post is continuation of previous post Create crystal report using asp.net. if you didn’t read previous post crystal reports please check that one then come to this one because I am continuing from previous post in that I explained clearly to create the database tables and bind the reports and display it on page. 

Now Open Default.aspx page and add one textbox, button in your aspx page because by entering username in textbox we will search for the records for that we need to add textbox and button control on top of report by using below code

<div>
Enter UserName: <asp:TextBox ID="txtUserName" runat="server"/>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" onclick="btnSubmit_Click" />
</div>
After add Textbox and button above the report design will be like this 


Now Open MySampleDBDataSet.xsd file in that select Fill data and right click on it and select Configure


Now one window will that contains select query like this


Now our requirement is to pass the parameter and get the values based on that parameter for that we need to modify the query

SELECT UserId, UserName, FirstName, LastName, Location FROM UserInformation

                                                 To

SELECT UserId, UserName, FirstName, LastName, Location FROM UserInformation WHERE (UserName LIKE '%' + @Name + '%')
After modify our query select query window will like this


After enter the query click Next and Next and click Finish. Now open our Default.aspx page in design mode and select objectdatasource and click on smart tag in right side and click on Configure Data Source


After click on Configure Data Source one window will open in that select TableAdapter and click Next


After click on Next button now we will see available Data Methods in select Tab select GetData Method and click Next


After click Next button Define Parameters window will open in that we need to specify parameters for GetMethod. In this window First select ControlName in Parameters box after that Parameters Source and ControlID Options will enable now select Control in Parameter Source dropdown and select your textbox controlID in ControlID dropdown that would be like below figure.


After fill all options click Finish button we completed set everything to send parameters now open Default.aspx page and double click on your Submit button and write the following code in codebehind

protected void btnSubmit_Click(object sender, EventArgs e)
{
ReportViewer1.LocalReport.Refresh();
}
Now build and run your application and check the output initially it won’t display any data once we type username in textbox and click on Submit button it will display the resultant data.

Demo


Please give your comments regarding above topic is it ok or not and if you like the post please share it.
  

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

22 comments :

Anonymous said...

thanks ...

shailesh said...

Great post. Thanks!

Anonymous said...

Nice post sir..

I want to display full details of customer purchased. After displaying details when i will click on particular row, want to display another report with full customer purchased details.

Please help me sir..
Thank you...

Anonymous said...

I'm using the code below to pass the value of a textbox from an ASP Page into a rdlc report but the report is loading non stop and there's no error showing, please help

using System;
using System.Data;
using System.Configuration;
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 Microsoft.Reporting.WinForms;
using Microsoft.Reporting.WebForms;
using System.Data.SqlClient;
using System.Collections;






public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{


//assigning textboxes to the session variables from the search page
this.TextBox1.Text = (string)( Session["Date_From"]) ;
this.TextBox2.Text = (string)( Session["Date_To"]);


this.ReportViewer1.LocalReport.ReportEmbeddedResource = "My_First_Solution.My_Report.rdlc";
ReportParameter rp = new ReportParameter("DateFrom", this.TextBox1.Text,false );
ReportParameter rp2 = new ReportParameter("DateTo", this.TextBox2.Text,false );
this.ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { rp, rp2 });
this.ReportViewer1.LocalReport.Refresh();



}

}

Hasan Istiak said...

i have data in session field. How can i print it through crystal report. Can Anyone give me solution. It needs me because i want to print user details. I want to show user name first and then details. So i want to show user name from session then details from database.

Rajkumar Palnati said...

Hi Suresh I am regular viewer to ur site.
This site helps me a lot
Thanks bro

Anonymous said...

Thanks you so much for step-by-step explanation.

Anonymous said...

how to pass parameter to cross tab crystal report inoredr to set column header as year. The year range is taken as input parameter.

parthi said...

good i gained lot ...

Anonymous said...

Good post......

Anonymous said...

Hi Suresh, thanks for the post.

I was trying to implement the solution. I am getting a error. When I first open the report, I see the error below the text box

"An error has occurred during report processing.
Exception has been thrown by the target of an invocation.Value cannot be null. Parameter name: CompName".

When I enter anything in the text box then only I get the report correctly. I want that initially it should open with all records.

Beeru choudhary said...

hey suresh you are superb!! i have learned a lot from your website/


Anonymous said...

An error has occurred during report processing.
Cannot create a data reader for dataset 'DataSet1'.
What does this error means..??

Bhaskar Singh said...

Thanks! A lot you help me very much!
It is simple,sober and excellent.

kapil bhati said...

Hello Suresh
I want make a report by report viewer.But Report Viewer Not Drag From Toolbox to .Aspx page. what is the prblm please tell me..Why report viewer not Drag from toolbox and drop to .aspx page.

Patel Raj said...

An error occurred during print dialong
"Operation is not valid due to the current state of the object."

reportViewer1.PrintDialog();

Rohit Gupta said...

Sir,I have one requirement regarding crystal report,how to generate report when the SQL query is passed from the text box,it should generate the report based on the query.
help me please

Thank You

Anonymous said...

good post

Anonymous said...

hi suresh

i am facing problem in crystal reporting in web application , i want to know about HTML reporting please post a example on this.

thanks

Saeel Chari said...

Hello Sir,
I have performed similar steps , I am using dropdownbox control. But the data is not displaying in report.
Please guide me.
Thanks in advance

sarita said...

http://www.aspdotnet-suresh.com/2011/11/how-to-pass-parameters-to-crystal.html

After click on Next button now we will see available Data Methods in select Tab select GetData Method and click Next but in my website next button is disable so i am not able to click on Next

shashi kiran said...
This comment has been removed by the author.

Give your Valuable Comments

Other Related Posts

© 2010-2012 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.