Search

Categories

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Send mail to the author(s) E-mail

# Sunday, 08 May 2011

To display:

image

I bring back a from SQL:

CONVERT(varchar(10), DATEADD(hh,13,VoucherRedemption.RedeemedAtUTC), 105) as RedeemedAtLocalShortDateInSQL

eg 14-02-2011

Then in RS.. Chart, Series Properties, Category Field put in eg RedeemedAtLocalShortDateInSQL

and in Axis Properties: Custom format:  ddd dd MMM

| | # 
# Wednesday, 09 February 2011

Showing how to get custom formatting of dates on the x axis.

image

image

 

Custom gradient colours:

image

Percentages

image

image

| | # 

In VS2010, .NET4 Webforms project:

How to make a Stand Alone Report – gui

create new website project (see RDLCTest2)

add ScriptManager and ReportViewer control to webpage

add Report1.rdlc file using right click on project, choose report, not report wizard

add DataSet1.xsd to project, and use query builder to make the correct sql and parameters

in Report1.rdlc, View Report Data, Add a DataSet, and point it to DataSet1, add a table and put in values

Wire up ReportViewer control to Report1.rdlc

This does the ObjectDataSource trick.

image

 

How to make a Stand Alone Report – wire up in code

webpage.aspx

has a ReportViewer control in it

      which points to an Report.rdlc file

code behind news up a DataSet.xsd

    called DataSetTableAdapter.TableAdapter

    then news up a ReportDataSource, and passes this DataTable into it calling it DataSet1

the Report.rdlc then knows about DataSet1

 

Another Example

// new up a table adapter which is part of SimpleReportDataSet
SimpleReportDataSetTableAdapters.ClientTableAdapter clientTableAdapter = new SimpleReportDataSetTableAdapters.ClientTableAdapter();
// get the data into a DataTable using the table adapter method
SimpleReportDataSet.ClientDataTable clientDataTable = clientTableAdapter.GetData();

// wire up populated DataTable to report
ReportDataSource reportDataSource = new ReportDataSource("Client", (System.Data.DataTable)clientDataTable);

ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(reportDataSource);
ReportViewer1.LocalReport.Refresh();
 
SimpleReportDataSet.xsd
 
image
 
When adding a new dataset in the Report I called it Client (same as the dataset in the xsd).  Put the dataset in the root of the directory for the designer to pick it up when doing new dataset.

image

Multiple Report Parameters and Passing Parameter to Dataset

image

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
GenerateClientDropDown();
btnRenderReport_Click(null,null);
}
}

public void GenerateClientDropDown()
{
LightSpeedContext<PocketVouchersUnitOfWork> _context = new LightSpeedContext<PocketVouchersUnitOfWork>("Development");
_context.Logger = new TraceLogger();
using (var uow = _context.CreateUnitOfWork())
{
var listOfClients = (from client in uow.Clients
select new
{
client.Name,
client.Id
}).Distinct();
ddlClients.DataSource = listOfClients;
ddlClients.DataTextField = "Name";
ddlClients.DataValueField = "Id";
ddlClients.DataBind();
}
}

protected void btnRenderReport_Click(object sender, EventArgs e)
{
// new up a table adapter which is part of SimpleReportDataSet
SimpleReportDataSetTableAdapters.ClientTableAdapter clientTableAdapter = new SimpleReportDataSetTableAdapters.ClientTableAdapter();
// get the data into a DataTable using the table adapter method
SimpleReportDataSet.ClientDataTable clientDataTable = clientTableAdapter.GetData(new Guid(ddlClients.SelectedValue));

// wire up populated DataTable to report
ReportDataSource reportDataSource = new ReportDataSource("Client", (System.Data.DataTable)clientDataTable);

// pass parameters to the report - nothing to do with datasets
ReportParameter totalRedeemedParam = new ReportParameter("TotalRedeemed", "7");
ReportParameter merchantNameParam = new ReportParameter("MerchantName", "testMerchantName");
ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { totalRedeemedParam, merchantNameParam });

ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(reportDataSource);
ReportViewer1.LocalReport.Refresh();
}
}

 

References

DataSet objects, a group of classes describing a simple in-memory relational database,

  • A DataSet object represents a schema (either an entire database or a subset of one). It can contain tables and relationships between those tables.
    • A DataTable object represents a single table in the database. It has a name, rows, and columns.
      • A DataView object overlays a DataTable and sorts the data (much like an SQL "order by" clause) and filters the records (much like an SQL "where" clause) if a filter is set. An in-memory index is used to facilitate these operations. All DataTables have a default filter, while any number of additional DataViews can be defined, reducing interaction with the underlying database and thus improving performance.
        • A DataColumn represents a column of the table, including its name and type.
        • A DataRow object represents a single row in the table; it allows reading and updating of values in that row, likewise retrieving any rows that are related to it through a primary-key foreign-key relationship.
| | # 
# Wednesday, 19 January 2011