Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi,
I need a use of microsoft report viewer in my college project which in c#.net...i tried to find a good tutorial for learnig it....www.gotreportviewer.com....but it is very confusing..
i need to provide the data source to the reportviwer through the code...but i coundn't figure out how can i do that....i tired many refrence which helped me provide the datasource through a wizard but it only showed the record of only one table...i need to show the record of 3 tables in one report viewer... by using join query....

sorry if i am not able to explain my problem clearly....please help me learn it....
Posted
Updated 24-Aug-11 5:49am
v2

1 solution

Okay that is very simple. Don't be frustrated. I guide you step by step. Please Follow it:

1. Create a project.

2. Add DataSet and Name it DataSet1.

3. In the TestDataSet.xsd file Click Right Mouse Button and add TableAdapter.In this case you need to put the correct connection string of your database and select "Use Sql Statement" and in the editor you put your Query here. You might also use the Query Builder to generate your Query.Then Just Click Next and proceed . When you finish this step you will get a DataTable and Method "Fill,GetData()" something like this.

Is it Okay. We have finished to design our DataSet right? In this DataSet you might send parameter or You might use your Object DataSource .I am not going with that now.I just give you the simple solution Okay.

Now see the AdapterName on the DataSet that you create earlier. In my case this is TestTableAdapter.

Now Select the Adapter Portion on the DataSet then On the property window set its Modifier is Public.This is very important.


Now Write a function like,

C#
public static DataSet1.EmployeeDataTable GetReportData()
        {
            DataSet1TableAdapters.EmployeeTableAdapter ta = new DataSet1TableAdapters.EmployeeTableAdapter();            
            return ta.GetData();           
        }



Here,

DataSet1.EmployeeDataTable-> DataSet1is my Dataset which is a namespace and EmployeeDataTableis my table name

DataSet1TableAdapters.EmployeeTableAdapter-> DataSet1TableAdapters is the adapter Container and EmployeeTableAdapter is my adapter.

That's fine Now we have also Data. This function returns the DataSet1.EmployeeDataTable so we might see our data in in this table. Got it right?

Now write another function to display the report

C#
public void DisplayReport(DataSet1.EmployeeDataTable dt)
        {
            try
            {
                if (dt != null)
                {
                    DataSource RDS=new DataSource();                    
                    reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
                    reportViewer1.LocalReport.ReportPath = "C:\\Users\\RASHIM\\Documents\\Visual Studio 2008\\Projects\\SSRS Test\\SSRS Test\\Report1.rdlc";
                    reportViewer1.LocalReport.DataSources.Clear();
                    reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1_Employee", dt));
                    reportViewer1.DocumentMapCollapsed = true;
                    reportViewer1.RefreshReport();
                }
            }
            catch (Exception oEx)
            {
                MessageBox.Show(oEx + "ShowReport");
            }
        }


Here,

reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1_Employee", dt));

DataSet1-> Dataset Name and Employee->Table name




That's all. Now When you call this Function with valid parameter your report will display. I hide lots of thing I guess you might do it by your own way. But main Two functions i am giving here.

If you are unable to display the report Please lemme know i will help you from my level best
 
Share this answer
 
v3
Comments
amsainju 24-Aug-11 13:40pm    
thank you for your kind help....i will try as u say....if i again encounter any problem, i will let u know thank you..
Md. Rashim Uddin 24-Aug-11 13:42pm    
Is it Helping you...Thanks God. And please feel free to submit your problem if you face any.

Thanks,
Rashim
Md. Rashim Uddin 24-Aug-11 13:44pm    
And please Mark it as corrected after you complete your task.
amsainju 24-Aug-11 14:12pm    
hey i did as u said... but the code show only one problem..
in the following line

reportViewer1.LocalReport.ReportPath = Server.MapPath(rptName);

the error is
the name Server does not exists in current context...

i am using these class libraries

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Microsoft.Reporting.WinForms;
using System.Web;

the code after running asked to add Microsoft.SqlServer.Server but it also didn't solve the problem..

help me with this

ok thanks for your help

Server
Md. Rashim Uddin 24-Aug-11 14:15pm    
Okay ..First Try WIth the Hard coded Path of the rdlc file. If it is work then we will use Server.MapPath

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900