C# Report Wizard

Generate report using Report Wizard

There are different ways to generate a report in C# using Visual Studio. In this tutorial, I am going to show you how to achieve this goal using Report Wizard available in Visual Studo 2010.
Now you have a new Windows Forms Application in Visual Studio 2010. Then you add a report to the project by right-clicking the name of the project under Solution Explorer. Select Add->New Item…Under Installed Template, select Reporting->Report Wizard. In the DataSet Properties dialog, you create a new data source by clicking the New… button .

dataset properties

In the next dialog, you choose Database. Then click the Next button.

database type

In the Choose a Database Model dialog, you select Dataset. By clicking the Next button, you will see another dialog that allows you create a connection to your SQL Server database. Click New Connection… button to create a new connection to the database.
After you select a table of the database to be used on your report, you will be backed to the DataSet Properties dialog. Click Next. In the Arrange Fields dialog, you drag and drop fields of the table into the Values box.

arrange fields

Then click Next. Then click Finish to finish the report setup task. Now you have a report. To display the report on your form, you have to add a ReportViewer from the Toolbox to the form. Then on Load method of the form, you write code as shown below to bind data to the report dynamically. You will change database name, table name, server name, user id, and password to yours.

SqlConnection con = null;
SqlDataAdapter adapter = null;
DataSet ds = new DataSet();
string DbName = "your_database_name";
string TblName = "table_name";
string conStr = "Server=MyServer; Database=" + DbName + ";User=your_username;Password=your_password;";
con = new SqlConnection();
con.ConnectionString = conStr;
adapter = new SqlDataAdapter("Select * From " + TblName, con);
adapter.Fill(ds, TblName);
DataTable dt = new DataTable();
this.reportViewer1.Visible = true;
ReportDataSource rpds = new ReportDataSource();
rpds.Name = "DataSet1";
rpds.Value = dt;
reportViewer1.LocalReport.ReportPath = "Report.rdlc";

database type


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.