Reporting

Create Stored Procedure

CREATE PROC GetDepartments
AS
	SELECT * FROM Department;
GO

Create Project Window Form with C#

View Video

Create Connection String

<connectionStrings>
    <add name="db" 
    	connectionString="Data Source=ServerDatabase;
    	Initial Catalog=DatabaseName;
    	Integrated Security=True" 
    	providerName="System.Data.SqlClient" />
 </connectionStrings>

Create Class Department

class Department
{
    public int Id { get; set; }
    public string Name { get; set; }
}

Create Class DepartmentProvider

using System.Collections.Generic;
using System.Data.SqlClient;
using System.Configuration;
class DepartmentProvider
{
	static string connectionString = ConfigurationManager.
		ConnectionStrings["db"].ConnectionString;	
}

Create GetDepartments

class DepartmentProvider{
	public static List GetDepartments(){
        using (SqlConnection connection = new SqlConnection(connectionString)){
            using (SqlCommand command = new SqlCommand("GetDepartments", connection)){
                command.CommandType = System.Data.CommandType.StoredProcedure;
                connection.Open();
                using (SqlDataReader reader = command.ExecuteReader()){
                    List list = new List();
                    while (reader.Read()){
                        list.Add(new Department { 
                        	Id = (int)reader["Id"], 
                        	Name = (string)reader["Name"] });
                    }
                    return list;
                }
            }
        }
    }
}

Create Reporting for Department

View Video

Set Datasource to ReportViewer

ReportDataSource dataSource = new ReportDataSource();
dataSource.Name = "DataSet1";
dataSource.Value = DepartmentProvider.GetDepartments();
reportViewer1.LocalReport.DataSources.Add(dataSource);
reportViewer1.LocalReport.ReportPath = "./../../ReportDepartment.rdlc";
//reportViewer1.LocalReport.ReportEmbeddedResource = "AppReporting.ReportDepartment.rdlc";
reportViewer1.RefreshReport();