02 July 2008

Client-Side Reporting with Visual Studio in C#

Yesterday i was try produce report by Crystal Report. Now i am using Client Side Report for my ASP.NET project.
The first drag and drop Microsoft Report Viewer to your web form. Give the id is RptViewer.
Create New DataSet, define the coloumn do you need. For example TblXXX(cola,colb).

dont forget for include namespace for (System.Data.SqlClient and Microsoft.Reporting.WebForms).
//namespace
using System.Data.SqlClient;
using Microsoft.Reporting.WebForms;




String VarSQL;
SqlDataAdapter VarRst;
DataSet ds = new DataSet();


//Define object for connection to DB you can create by your self.
ClassDB.ClassToDB db = new ClassDB.ClassToDB();

VarSQL = "SELECT cola,colb FROM Tblzzz";


//result from method ExecuteDataAdapter is Data Adapter
VarRst = db.ExecuteDataAdapter(VarSQL);
VarRst.Fill(ds, "report");

ReportDataSource dataSource = new ReportDataSource("DataSet1_TblXXXX", ds.Tables[0]);
RptViewer.Reset();
RptViewer.LocalReport.ReportPath = Server.MapPath("rpt/rpt_fuel.rdlc");
RptViewer.LocalReport.DataSources.Add(dataSource);

1 Comments:

At Monday, July 26, 2010 6:12:00 PM , Anonymous moosetracker said...

Thanks,
My origianl tutorial set up the dataset to report bind with a datareader. And I could not figure out how to alter that code to bind the ds without the datareader..

My code to bind to the ds is different then yours but your binding to the report worked for my code with one additional line.

Just before the reset command I needed to put:

dataSource.Name = "dsXSD_dstable";

where dsXSD is the name of my dataset.xsd, and dsTable is the name of the table layout in my xsd.

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home