I searched the forum but couldn't find anyone with the same problem with me. They were close but didn't help me solve my issue.
I'm trying to learn how to make the sub-report get data from SQL Server based on a primary key passed from the main-report.
An example: Main report displays all student names and the sub-report would display all their contact phone numbers.
A visual: Bobby Smith
Home Phone: 555-1212
Cell Phone: 555-2323
Work Phone: 555-3434
Jane Doe
Home Phone: 555-2020
Cell Phone: 555-3030
Work Phone: Null
Ginger Doe
Home Phone: 555-5062
Cell Phone: 555-9586
Work Phone: 555-2356
SQL TABLES:
Student
------------------------------------
Student ID | Name
------------------------------------
1 | Bobby Smith
2 | Jane Doe
3 | Ginger Doe
Phone
------------------------------------
Phone ID | Student ID | Number | Type
------------------------------------
1 | 1 | 555-1212 | Home
2 | 1 | 555-2323 | Cell
3 | 1 | 555-3434 | Work
4 | 2 | 555-2020 | Home
5 | 2 | 555-3030 | Cell
6 | 2 | 555-5062 | Home
7 | 3 | 555-9586 | Cell
8 | 3 | 555-2356 | Work
What I have working:
I have the main report listing all the student's names by creating a dataset (.xsd) in my App_Code folder and adding a TableAdapter with the query "Select * from Student". I then created a report (.rdlc) and dragged and dropped the Name field from the dataset.
This all works fine.
Now I'm trying to add the sub-report to list the student's phone number and that is where I'm stuck.
I started doing the same thing as the main form. First create my dataset (.xsd) in my App_Code folder and adding a TableAdapter. I tried putting the query as "Select * from Phone where Phone.StudentID = @StudentID". I used @StudentID because I want to
be able to send a variable to get the results (that's what I'm thinking). Then I try to create the report (.rdlc) and drag the phone fields from the dataset. I also try to set the Parameters and now I'm totally lost because the sub-report bombs all the time
with the message "error subreport could not be shown". Any help would be appreciated.
I know I can use a table or matrix to accomplish this, but I want to learn to use SubReports. THANKS!!!
bdotnet
Member
1 Points
4 Posts
Sub report query based on main report (Microsoft Report Viewer)
Jun 08, 2009 10:02 PM|LINK
Hi
I searched the forum but couldn't find anyone with the same problem with me. They were close but didn't help me solve my issue.
I'm trying to learn how to make the sub-report get data from SQL Server based on a primary key passed from the main-report.
An example:
Main report displays all student names and the sub-report would display all their contact phone numbers.
A visual:
Bobby Smith
Jane Doe
Ginger Doe
SQL TABLES:
Student
------------------------------------
Student ID | Name
------------------------------------
1 | Bobby Smith
2 | Jane Doe
3 | Ginger Doe
Phone
------------------------------------
Phone ID | Student ID | Number | Type
------------------------------------
1 | 1 | 555-1212 | Home
2 | 1 | 555-2323 | Cell
3 | 1 | 555-3434 | Work
4 | 2 | 555-2020 | Home
5 | 2 | 555-3030 | Cell
6 | 2 | 555-5062 | Home
7 | 3 | 555-9586 | Cell
8 | 3 | 555-2356 | Work
What I have working:
I have the main report listing all the student's names by creating a dataset (.xsd) in my App_Code folder and adding a TableAdapter with the query "Select * from Student". I then created a report (.rdlc) and dragged and dropped the Name field from the dataset. This all works fine.
Now I'm trying to add the sub-report to list the student's phone number and that is where I'm stuck.
I started doing the same thing as the main form. First create my dataset (.xsd) in my App_Code folder and adding a TableAdapter. I tried putting the query as "Select * from Phone where Phone.StudentID = @StudentID". I used @StudentID because I want to be able to send a variable to get the results (that's what I'm thinking). Then I try to create the report (.rdlc) and drag the phone fields from the dataset. I also try to set the Parameters and now I'm totally lost because the sub-report bombs all the time with the message "error subreport could not be shown". Any help would be appreciated.
I know I can use a table or matrix to accomplish this, but I want to learn to use SubReports. THANKS!!!