Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ReportViewer in asp.net vb.net

Status
Not open for further replies.

meesho

Programmer
Dec 9, 2011
2
KW
Hello ppl, Please i have been dying to get this to work but no help what so ever, i tried so many ways and so many searches but i always reached a dead end..

I have a ReportWizard that i created, an .rdlc file, and i have a report Viewer tool in my .aspx page that i linked it to my .rdlc report, and i have a DataSet1.xsd Data Set also created, in my data set, i have put this SQL statement:

VB.NET Syntax (Toggle Plain Text)
SELECT Case_Number, Staff_FName, Staff_LName, Branch_Dept, Case_Category, Case_Date, Closed_Date, Problem, Initial_Solution, Customer_Name, Acc_NumFROM SQ_IMSWHERE (Case_Date >= '@date1') AND (Case_Date <= '@date2')SELECT Case_Number, Staff_FName, Staff_LName, Branch_Dept, Case_Category, Case_Date, Closed_Date, Problem, Initial_Solution, Customer_Name, Acc_Num
FROM SQ_IMS
WHERE (Case_Date >= '@date1') AND (Case_Date <= '@date2')
Now if i want my user to chose 2 values from 2 textboxes in my aspx page, and then send it to the report to be generated, i guessed that i have to use parameters, and that is why i used it in my WHERE statement, the @date1 and @date2, but the problem now, is that i am stuck on what to write in my button click, please if someone can give me the code, or show me a hint of that code, in VB.NET please, i would really really apreciate it, a code to send the parameters to the ReportViewer and generate the report, because i completly dont know how to use reports and never worked on them before, i really really need it urgently, and thanx alot in advance.
 
assuming you have two pages 1. the input screen 2. the page with a report viewer.

On the input screen add 2 text boxes, 1 for each date, and a button.
add validation to make sure the user enters a valid date. then in the button click event on the server
Code:
protected void Button1_Click(object sender, EventArgs e)
{
   if(IsValid == false) return; //don't proceed if there are validation errors

   var date1 = DateTime.Parse(textbox1.Text);
   var date2 = DateTime.Parse(textbox2.Text);
   var url = string.Format(page2.aspx?date1={0:mm-dd-yy}&date2={1:mm-dd-yy}", date1, date2);

   Response.Redirect(url, false);
}
this will redirect the user to page 2 with the date values in the query string. The next step is to get the values out of the query string and into the report. do this in the page load event.
Code:
protected override void OnLoad(EventArgs e)
{
   base.OnLoad(e);

   if(IsPostBack) return;

   var date1 = DateTime.Parse(Request.QueryString["date1"]);
   var date2 = DateTime.Parse(Request.QueryString["date2"]);
   //you now have the dates to pass to the report/viewer/data adapter/etc. How you do that depends on how you query the database and populate the report.
}
this is C# code, but translating to VB is simple enough that you should be able to figure it out.

Jason Meckley
Senior Programmer

faq855-7190
faq732-7259
My Blog
 
Thanx for the reply, but u didnt get me right, the report viewer is a tool, and its called reportViewer1, this tool is inside my aspx page, which means, i only have one page only not 2 pages, i dobnt thing querysring will do, this might need a parameter:S
 
yes, I'm familiar with the report viewer object (not tool). ultimately you will need a parameter. how you get the user input into the value is up to you.

if you don't have 2 pages. you can
1. create another page for the user input
2. alter the way the "view report" page works.

now making the assumption you have a single page. and this page contains
1. 2 inputs for dates and the proper validation
2. a button
3. the report

the click event of the button would look like this
Code:
if(IsValid == false) return; //don't proceed if there are validation errors

   var date1 = DateTime.Parse(textbox1.Text);
   var date2 = DateTime.Parse(textbox2.Text);

//you now have the dates to pass to the report/viewer/data adapter/etc. How you do that depends on how you query the database and populate the report.
if this doesn't describe your scenario please post the relevant code and markup.

Jason Meckley
Senior Programmer

faq855-7190
faq732-7259
My Blog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top