﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>IT博客-玄铁剑-文章分类-Report</title><link>http://www.cnitblog.com/MartinYao/category/4944.html</link><description>成功的途径：抄，创造，研究，发明...</description><language>zh-cn</language><lastBuildDate>Mon, 26 Sep 2011 13:52:43 GMT</lastBuildDate><pubDate>Mon, 26 Sep 2011 13:52:43 GMT</pubDate><ttl>60</ttl><item><title>Using the ASP.NET 2.0 ReportViewer in Local Mode</title><link>http://www.cnitblog.com/MartinYao/articles/32432.html</link><dc:creator>玄铁剑</dc:creator><author>玄铁剑</author><pubDate>Sat, 25 Aug 2007 15:00:00 GMT</pubDate><guid>http://www.cnitblog.com/MartinYao/articles/32432.html</guid><wfw:comment>http://www.cnitblog.com/MartinYao/comments/32432.html</wfw:comment><comments>http://www.cnitblog.com/MartinYao/articles/32432.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/MartinYao/comments/commentRss/32432.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/MartinYao/services/trackbacks/32432.html</trackback:ping><description><![CDATA[<p>There are a good amount of materials on the net about &#8220;SQL Reporting Services in Server Mode&#8221; but it took me a while to research on using &#8220;Local Mode&#8221;, especially when parameters are involved.</p>
<p>The reason to use &#8220;Local Mode&#8221; instead of &#8220;Server Mode&#8221; is that in &#8220;Server Mode&#8221;, the client makes a report request to the server. The server generates the report and then sends it to the client. While it is more secure, a large report will degrade performance due to transit time from server to browser. In &#8220;Local Mode&#8221;, reports are generated at the client. No connection to the &#8220;SQL Server Reporting Services Server&#8221; is needed for local mode. Large reports will not increase wait time.</p>
<p>So here is an article on how to generate reports using the ASP.NET 2.0 <code>ReportViewer</code> web server control via Local Mode with a parameterized stored procedure. I am using ASP.NET 2.0, Visual Studio 2005, and SQL Server 2005 with Application Block. If you are not using Microsoft Application Block, just call the stored procedure via the SQL <code>Command</code> object without using the SQL <code>Helper</code> class in the example.</p>
<p>Using the Northwind database, our example will prompt the user for a category from a dropdown list and display all the products under the selected category.</p>
<h3>Step 1: Create a parameterized stored procedure</h3>
<pre lang=sql><span class=vb-function>ALTER</span> <span class=vb-function>PROCEDURE</span>  ShowProductByCategory(@CategoryName <span class=cpp-keyword>nvarchar</span>(<span class=vb-literal>15</span>) )
<span class=vb-function>AS</span>
<span class=vb-function>SELECT</span>  Categories.CategoryName, Products.ProductName,
Products.UnitPrice, Products.UnitsInStock
<span class=vb-function>FROM</span>    Categories <span class=vb-function>INNER</span> <span class=vb-function>JOIN</span> Products <span class=vb-function>ON</span>
Categories.CategoryID = Products.CategoryID
<span class=vb-function>WHERE</span>   CategoryName=@CategoryName
<span class=vb-function>RETURN</span></pre>
<h3>Step 2: Create a DataTable in a typed DataSet using the DataSet Designer</h3>
<p>Under Solution Explorer, right-click on the <em>App_Code</em> folder. Select &#8220;Add New Item&#8221;. Select &#8220;DataSet&#8221;. Name your dataset, e.g., <em>DataSetProducts.xsd</em>, and click Add. The TableAdapter Configuration Wizard should appear automatically, if not, right click anywhere on the DataSet Designer screen and select &#8220;Add&#8221; from the context menu. Select the &#8220;TableAdapter&#8221; to bring up the wizard. Follow the wizard to create your data table. I chose &#8220;Use existing stored procedures&#8221; as the command type and specified &#8220;ShowProductByCategory&#8221; as the Select command. I also highlighted &#8220;CategoryName&#8221; as the Select procedure parameter.</p>
<p>The results from the stored procedure created in step 1 will eventually be placed into this data table created in step 2 (Fig. 1). Report data is provided through a data table.</p>
<p><img height=450 src="http://www.codeproject.com/aspnet/ReportViewer/1.jpg" width=600></p>
<p><strong>Fig. 1</strong> DataSetProducts.xsd contains a <code>DataTable</code> to be used as a report data source.</p>
<h3>Step 3: Create a report definition</h3>
<p>Under Solution Explorer, right-click and select &#8220;Add New Item&#8221;. Select the &#8220;Report&#8221; template. I will use the default name <em>Report.rdlc</em> in this example. Click &#8220;Add&#8221; to add <em>Report.rdlc</em> to your project. &#8220;rdl&#8221; stands for Report Definition Language. The &#8220;c&#8221; stands for Client. Hence, the extension <em>.rdl</em> represents a server report. The extension <em>.rdlc</em> represents a local report.</p>
<p>Drag a &#8220;<code>Table</code>&#8221; from the Toolbox onto the report designer screen (Fig.2). The Toolbox display here is specific to the report template. It shows controls to be used in a report as opposed to controls to be used in a web form. The &#8220;Table&#8221; has three bands, the header, detail, and the footer bands.</p>
<p>A &#8220;<code>Table</code>&#8221; is a data region. A data region is used to display data-bound report items from underlying datasets. Although a report can have multiple data regions, each data region can display data from only one <code>DataSet</code>. Therefore, use a stored procedure to link multiple tables into a single <code>DataSet</code> to feed the report.</p>
<p><img height=450 src="http://www.codeproject.com/aspnet/ReportViewer/2.jpg" width=600></p>
<p><strong>Fig. 2</strong> Toolbox contains controls specific to the report template.</p>
<p>Open up the &#8220;Website Data Sources&#8221; window (Fig.3). Locate the &#8220;<code>DataSetProducts</code>&#8221; <code>DataSet</code> (created in Step 2). Expand to see the columns in the <code>DataTable</code> &#8220;<code>ShowProductByCategory</code>&#8221;. The table is named &#8220;ShowProductByCategory&#8221; because we chose &#8220;Use existing stored procedure&#8221; in the TableAdapter Configuration Wizard. And our procedure name is &#8220;ShowProductByCategory&#8221;.</p>
<p>Drag the column &#8220;ProductName&#8221; from the &#8220;Website Data Sources&#8221; window, and drop it in the Detail row (middle row). Drag &#8220;UnitPrice&#8221; into the middle row-second column and &#8220;UnitsInStock&#8221; into the last column. The header is automatically displayed. You can right click on any field in the detail row (e.g., right click on &#8220;Unit Price&#8221;) and bring up the context menu. Select Properties from the context menu. Select Format tab to format the &#8220;Unit Price&#8221; and &#8220;Units In Stock&#8221; accordingly.</p>
<p><img height=450 src="http://www.codeproject.com/aspnet/ReportViewer/3.jpg" width=600></p>
<p><strong>Fig 3</strong>. Website Data Sources window shows typed datasets in your app and its columns.</p>
<h3>Step 4: Drag a ReportViewer web server control onto an .aspx form</h3>
<p>Drag a <code>DropDownList</code> control onto a new web form (Fig. 4). Use the &#8220;Choose Data Source&#8221; option from the &#8220;DropDownList Task&#8221; to bind the <code>CategoryName</code> field from the Category table. Remember to enable autopostback. Users can then make their selection as an input to the stored procedure. While I am using a <code>DropDownList</code> in this example, you can use textboxes and other controls to prompt users for additional input.</p>
<p>Drag a <code>ReportViewer</code> web server control onto the web form. Set its <code>Visible</code> property to <code lang=cs><span class=cs-keyword>false</span></code>. Also notice, the <code>ReportViewer</code> web server control in ASP.NET 2.0 provides exporting capability. You can select between Excel format or PDF format. However, I find that what you see on screen is not always what you get from the printer. You will have to experiment with the output format further.</p>
<p><img height=450 src="http://www.codeproject.com/aspnet/ReportViewer/4.jpg" width=600></p>
<p><strong>Fig. 4</strong> Set this web page as the StartUp page.</p>
<p>Next, bring up the smart tag of the <code>ReportViewer</code> control (Fig. 5). Select &#8220;<em>Report.rdlc</em>&#8221; in the &#8220;Choose Report&#8221; dropdown list. &#8220;<em>Report.rdlc</em>&#8221; was created in Step 3. Local Reports have the extension <em>.rdlc</em>. Server Reports are labeled with <em>.rdc</em>.</p>
<p><img height=450 src="http://www.codeproject.com/aspnet/ReportViewer/5.jpg" width=600></p>
<p><strong>Fig. 5</strong> Associate the report definition file (<em>.rdlc</em>) to the <code>ReportViewer</code> control</p>
<h3>Step 5: Write source code for the &#8220;Run Report&#8221; button to generate the report based on user selections</h3>
<p>Don&#8217;t forget to include the &#8220;<code>Microsoft.Reporting.WebForms</code>&#8221; namespace in your code-behind file.</p>
<div class=precollapse id=premain1 style="WIDTH: 100%"><img id=preimg1 style="CURSOR: hand" height=9 src="http://www.codeproject.com/images/minus.gif" width=9 preid="1"><span id=precollapse1 style="MARGIN-BOTTOM: 0px; CURSOR: hand" preid="1"> Collapse</span></div>
<pre lang=cs id=pre1 style="MARGIN-TOP: 0px"><span class=cs-keyword>using</span> System;
<span class=cs-keyword>using</span> System.Data;
<span class=cs-keyword>using</span> System.Data.SqlClient;
<span class=cs-keyword>using</span> System.Configuration;
<span class=cs-keyword>using</span> System.Collections;
<span class=cs-keyword>using</span> System.Web;
<span class=cs-keyword>using</span> System.Web.Security;
<span class=cs-keyword>using</span> System.Web.UI;
<span class=cs-keyword>using</span> System.Web.UI.WebControls;
<span class=cs-keyword>using</span> System.Web.UI.WebControls.WebParts;
<span class=cs-keyword>using</span> System.Web.UI.HtmlControls;
<span class=cs-keyword>using</span> Microsoft.ApplicationBlocks.Data;
<span class=cs-keyword>using</span> Microsoft.Reporting.WebForms;
<span class=cs-keyword>public</span> partial <span class=cs-keyword>class</span> ReportViewerLocalMode : System.Web.UI.Page
{
<span class=cs-keyword>public</span> <span class=cs-keyword>string</span> thisConnectionString =
ConfigurationManager.ConnectionStrings[
<span class=cpp-string>"NorthwindConnectionString"</span>].ConnectionString;
<span class=cs-comment>/*I used the following statement to show if you have multiple
input parameters, declare the parameter with the number
of parameters in your application, ex. New SqlParameter[4]; */</span>
<span class=cs-keyword>public</span> SqlParameter[] SearchValue = <span class=cs-keyword>new</span> SqlParameter[<span class=cs-literal>1</span>];
<span class=cs-keyword>protected</span> <span class=cs-keyword>void</span> RunReportButton_Click(<span class=cs-keyword>object</span> sender, EventArgs e)
{
<span class=cs-comment>//ReportViewer1.Visible is set to false in design mode</span>
ReportViewer1.Visible = <span class=cs-keyword>true</span>;
SqlConnection thisConnection = <span class=cs-keyword>new</span> SqlConnection(thisConnectionString);
System.Data.DataSet thisDataSet = <span class=cs-keyword>new</span> System.Data.DataSet();
SearchValue[<span class=cs-literal>0</span>] = <span class=cs-keyword>new</span> SqlParameter(<span class=cpp-string>"@CategoryName"</span>,
DropDownList1.SelectedValue);
<span class=cs-comment>/* Put the stored procedure result into a dataset */</span>
thisDataSet = SqlHelper.ExecuteDataset(thisConnection,
<span class=cpp-string>"ShowProductByCategory"</span>, SearchValue);
<span class=cs-comment>/*or   thisDataSet = SqlHelper.ExecuteDataset(thisConnection,
"ShowProductByCategory", dropdownlist1.selectedvalue);
if you only have 1 input parameter  */</span>
<span class=cs-comment>/* Associate thisDataSet  (now loaded with the stored
procedure result) with the  ReportViewer datasource */</span>
ReportDataSource datasource = <span class=cs-keyword>new</span>
ReportDataSource(<span class=cpp-string>"DataSetProducts_ShowProductByCategory"</span>,
thisDataSet.Tables[<span class=cs-literal>0</span>]);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(datasource);
<span class=cs-keyword>if</span> (thisDataSet.Tables[<span class=cs-literal>0</span>].Rows.Count == <span class=cs-literal>0</span>)
{
lblMessage.Text = <span class=cpp-string>"Sorry, no products under this category!"</span>;
}
ReportViewer1.LocalReport.Refresh();
}
}</pre>
<h3>Step 6: Build and Run the Report</h3>
<p>Press F5 to run the <em>.aspx</em>. Click on the &#8220;Run Report&#8221; button to see the list of products based on the selected category from the dropdown list (Fig. 6).</p>
<p><img height=450 src="http://www.codeproject.com/aspnet/ReportViewer/6.jpg" width=600></p>
<p><strong>Fig. 6</strong> Click on the &#8220;Run Report&#8221; button to generate a local report</p>
<p>Be sure to add reference of the <code>ReportViewer</code> to your web app, and note that your <code>ReportViewer</code> web server control has registered an HTTP handler in the <em>web.config</em> file. Your <em>web.config</em> file should have the following string:</p>
<pre lang=xml>&lt;httpHandlers&gt;
&lt;add path="Reserved.ReportViewerWebControl.axd" verb="*"
type="Microsoft.Reporting.WebForms.HttpHandler,
Microsoft.ReportViewer.WebForms,
Version=8.0.0.0, Culture=neutral,
PublicKeyToken=?????????????"
validate="false" /&gt;
&lt;/httpHandlers&gt;</pre>
<p>When you use the Visual Studio 2005 <code>ReportViewer</code> web server control in your website, you will need to copy the "<em>C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages\ReportViewer\ReportViewer.exe</em>" to your server and run it before you post those web pages with the <code>ReportViewer</code> control.</p>
<p>Well, there you have it. This is a simple example of creating a report in local mode. I hope you find the example useful. Happy computing!</p>
<img src ="http://www.cnitblog.com/MartinYao/aggbug/32432.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/MartinYao/" target="_blank">玄铁剑</a> 2007-08-25 23:00 <a href="http://www.cnitblog.com/MartinYao/articles/32432.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Applied MS Reporting Services 101 using Smart Client</title><link>http://www.cnitblog.com/MartinYao/articles/32431.html</link><dc:creator>玄铁剑</dc:creator><author>玄铁剑</author><pubDate>Sat, 25 Aug 2007 14:55:00 GMT</pubDate><guid>http://www.cnitblog.com/MartinYao/articles/32431.html</guid><wfw:comment>http://www.cnitblog.com/MartinYao/comments/32431.html</wfw:comment><comments>http://www.cnitblog.com/MartinYao/articles/32431.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/MartinYao/comments/commentRss/32431.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/MartinYao/services/trackbacks/32431.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Download source files - 70 Kb Image: 1&nbsp;Introduction&nbsp;I still remember it was a neatly done report that got me my first pay raise (every one likes pay raise right?).&nbsp; Ever s...&nbsp;&nbsp;<a href='http://www.cnitblog.com/MartinYao/articles/32431.html'>阅读全文</a><img src ="http://www.cnitblog.com/MartinYao/aggbug/32431.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/MartinYao/" target="_blank">玄铁剑</a> 2007-08-25 22:55 <a href="http://www.cnitblog.com/MartinYao/articles/32431.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Integrating Microsoft Access DB, SQL Reporting Services and Visual Studio .NET</title><link>http://www.cnitblog.com/MartinYao/articles/32430.html</link><dc:creator>玄铁剑</dc:creator><author>玄铁剑</author><pubDate>Sat, 25 Aug 2007 14:49:00 GMT</pubDate><guid>http://www.cnitblog.com/MartinYao/articles/32430.html</guid><wfw:comment>http://www.cnitblog.com/MartinYao/comments/32430.html</wfw:comment><comments>http://www.cnitblog.com/MartinYao/articles/32430.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/MartinYao/comments/commentRss/32430.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/MartinYao/services/trackbacks/32430.html</trackback:ping><description><![CDATA[In this article I would like to demonstrate how we can leverage the SQL Reporting Services feature on to a Microsoft Access database using Visual Studio .NET as IDE. Let me initiate my discussion with a brief introduction to the SQL Reporting Services and its classical features.
<p>&#160;</p>
<h2>SQL Server Reporting Services:</h2>
<p>Microsoft has added reporting capabilities to SQL <a class=iAs style="FONT-WEIGHT: normal; FONT-SIZE: 100%; PADDING-BOTTOM: 1px; COLOR: darkgreen; BORDER-BOTTOM: darkgreen 0.07em solid; BACKGROUND-COLOR: transparent; TEXT-DECORATION: underline" href="http://www.codeproject.com/sqlrs/SQLReportingServcie.asp#" target=_blank itxtdid="4280861">Server</a> 2000. With the rollout of SQL Server 2000 Reporting Services, we can now generate reports from SQL Server, Access, Oracle, Open Database Connectivity (ODBC) and OLE DB data sources. Microsoft SQL Server 2000 Reporting Services is designed with a modular, distributed architecture to help achieve both scalability and flexibility. Processing is distributed across multiple components that can be extended and integrated into custom solutions.</p>
<ul>
    <li>Server based reporting engines.
    <li>Create reports with tables, graphs with data extracted from the database.
    <li>Can contain data from relational and/or multidimensional data sources.
    <li>Reports are viewed over the web. </li>
</ul>
<p>During report processing, a report definition is retrieved from the Report Server database and used with data from the data source to create a report. Report processing begins with a published report definition. A report definition contains one or more queries, layout information, and code or expressions. Report and data processing are combined to create a dataset with layout information in an intermediate format that can be saved for fast retrieval, or directed to a rendering extension that processes it into a format that the user can view. After processing is completed, reports are compiled as a common language runtime (CLR) assembly and executed on the Report Server.</p>
<p>When a report is accessed, either on-demand or as a result of a subscription, the Report Server decides whether to generate the report from scratch or use a cached snapshot. Because report rendering is separate from the initial processing of the report data, the same report may be rendered in different formats through the use of rendering extensions. Reporting Services includes the following rendering extensions:</p>
<ul>
    <li>HTML
    <li>Microsoft Excel
    <li>Image / TIFF
    <li>PDF
    <li>Comma-separated variables
    <li>XML </li>
</ul>
<p>Delivery extensions are responsible for delivering rendered reports on a schedule or other event to various locations. Reporting Services includes the following delivery extensions like e-mail and file system.</p>
<p>I would like to make use of the following examples to elucidate the integration process.</p>
<h2>Example1- Integration of SQL Reporting Services and Microsoft VS.NET:</h2>
<p>The below example provides a simple walk-through on creating and displaying a report in an ASP.NET Web page using Reporting Services. I assume that you have already downloaded and installed Reporting Services and are using Visual Studio .NET 2003 as your IDE.</p>
<ol>
    <li><strong>Project Creation</strong> - In order to create a Reporting Services project, select Report Project Wizard template in <a class=iAs style="FONT-WEIGHT: normal; FONT-SIZE: 100%; PADDING-BOTTOM: 1px; COLOR: darkgreen; BORDER-BOTTOM: darkgreen 0.07em solid; BACKGROUND-COLOR: transparent; TEXT-DECORATION: underline" href="http://www.codeproject.com/sqlrs/SQLReportingServcie.asp#" target=_blank itxtdid="4166552">Business</a> Intelligence Project using Visual Studio .NET 2003.
    <p><img height=387 src="http://www.codeproject.com/sqlrs/SQLReportingServcie/figure1.jpg" width=531></p>
    <p><strong>Figure 1</strong></p>
    <li><strong>Datasource &amp; SQL Query</strong>: Next we have to create a data source and SQL statement for the report to be generated.
    <p><img height=428 src="http://www.codeproject.com/sqlrs/SQLReportingServcie/figure2.jpg" width=540></p>
    <p><strong>Figure 2</strong></p>
    <li><strong>Report Type</strong> - Tabular format type is a basic row-by-column report presentation.
    <li><strong>Table Design</strong> - The Report Wizard design option has some great options for rolling up, grouping, and summarizing your data.
    <li><strong>Table Style</strong> &#8211; Available table style options are Bold, Casual, Compact, Corporate and Plain.
    <li><strong>Report Server</strong> &#8211; We have to specify the Report Server details to which our report will be deployed.
    <li><strong>Summary Screen</strong> - The final screen of the Report Wizard displays the summary of the above feed in information.
    <p><img height=483 src="http://www.codeproject.com/sqlrs/SQLReportingServcie/figure3.jpg" width=520></p>
    <p><strong>Figure 3</strong></p>
    </li>
</ol>
<p>The report designer has three tabs namely:</p>
<ul>
    <li><strong>Preview Tab</strong>: It is used to preview the report.
    <li><strong>Data Tab</strong>: It offers options to modify the datasource and SQL query.
    <li><strong>Layout Tab</strong>: It helps to fix up the appearance of the report (colors, fonts, grid lines, etc.). </li>
</ul>
<p><img height=399 src="http://www.codeproject.com/sqlrs/SQLReportingServcie/figure4.jpg" width=550></p>
<p><strong>Figure 4</strong></p>
<h2>Example 2 - Integration of Reporting Services, Access DB and Microsoft VS.NET:</h2>
<p>The second example provides a quick walk-through on displaying an Access report in an ASP.NET Web page using Reporting Services. It assumes that you have already reviewed the above example on VS.NET and Reporting Services integration.</p>
<ol>
    <li>Let&#8217;s assume that we have already created a &#8220;Supplier&#8221; Access report which is populated using the &#8220;Supplier&#8221; table. In figure 5, you would see the Access report.
    <p><img height=460 src="http://www.codeproject.com/sqlrs/SQLReportingServcie/figure5.jpg" width=550></p>
    <p><strong>Figure 5</strong></p>
    <li>Preview of Access report in Access environment:
    <p><img height=407 src="http://www.codeproject.com/sqlrs/SQLReportingServcie/figure6.jpg" width=550></p>
    <p><strong>Figure 6</strong></p>
    <li>Now open the sample report project created using the above example (example1) illustration. In order to import the Access reports, click on the Project tab and navigate to Import Reports option and select Microsoft Access database.
    <p><img height=412 src="http://www.codeproject.com/sqlrs/SQLReportingServcie/figure7.jpg" width=550></p>
    <p><strong>Figure 7</strong></p>
    <li>On selecting the Access option, it will allow the user to select the Access database from which he intends to generate the report.
    <p><img height=409 src="http://www.codeproject.com/sqlrs/SQLReportingServcie/figure8.jpg" width=550></p>
    <p><strong>Figure 8</strong></p>
    <li>Now open the Supplier report in Visual Studio .NET. You will observe in the Build section - &#8220;Report Suppliers imported&#8221; message displayed. And also on the Solution Explorer, you will find that <em>Supplier.rdl</em> is added to the report project.
    <p><img height=411 src="http://www.codeproject.com/sqlrs/SQLReportingServcie/figure9.jpg" width=550></p>
    <p><strong>Figure 9</strong></p>
    <li>On clicking the DataSet option on the &#8220;Data&#8221; tab, you will find that the following information about the Data Source, Command Type and Query String are displayed to the user:
    <p><img height=412 src="http://www.codeproject.com/sqlrs/SQLReportingServcie/figure10.jpg" width=550></p>
    <p><strong>Figure 10</strong></p>
    <li>Using the Preview Tab, you will be able to view the Access report.
    <p><img height=411 src="http://www.codeproject.com/sqlrs/SQLReportingServcie/figure11.jpg" width=550></p>
    <p><strong>Figure 11</strong></p>
    </li>
</ol>
<h2>Conclusion</h2>
<p>Hope this article would have provided insight on how to leverage the SQL Reporting Services capability to Access reports, using the Visual Studio .NET IDE.</p>
<!-- Article Ends -->
<script src="/script/togglePre.js" type=text/javascript></script>
<h2>&nbsp;</h2>
<img src ="http://www.cnitblog.com/MartinYao/aggbug/32430.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/MartinYao/" target="_blank">玄铁剑</a> 2007-08-25 22:49 <a href="http://www.cnitblog.com/MartinYao/articles/32430.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ReportingServices:Application Developer </title><link>http://www.cnitblog.com/MartinYao/articles/32429.html</link><dc:creator>玄铁剑</dc:creator><author>玄铁剑</author><pubDate>Sat, 25 Aug 2007 14:47:00 GMT</pubDate><guid>http://www.cnitblog.com/MartinYao/articles/32429.html</guid><wfw:comment>http://www.cnitblog.com/MartinYao/comments/32429.html</wfw:comment><comments>http://www.cnitblog.com/MartinYao/articles/32429.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/MartinYao/comments/commentRss/32429.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/MartinYao/services/trackbacks/32429.html</trackback:ping><description><![CDATA[<a href="http://www.codeproject.com/useritems/ReportingServices/SSRS_1.zip">Download SSRS_1.zip - 1,784.1 KB</a>
<h2>How To Create Sample Reports Using SSRS:</h2>
<h2>Introduction</h2>
<p style="TEXT-ALIGN: justify">Microsoft has come up with its own reporting service, in conjuction with SQL <a href="http://www.codeproject.com/useritems/Start_SSRS.asp" target=_blank>server</a> database to introduce the Microsoft SQL Server Reporting services[SSRS]. It provides projects of type Business Intelligence Project thus enabling not only large companies but also medium-sized and small companies also to earn from its benefits. This aids in better business decisions too. </p>
<p style="TEXT-ALIGN: justify">SSRS provides several extensions towards the data rendering, delivery and security of reports thereby allowing it to have a higher programmable ability. This innovative approach enables reports to be created with lesser development effort[compared to other reporting services], along with customized security options. </p>
<p style="TEXT-ALIGN: justify">SSRS is a comprehensive reporting platform whereby reports are stored on a centralized web server (or set of servers). Because reports are centralized, users run reports from one place. Having centralized reports also means that report deployment is quite simplified. </p>
<h2>Architecture</h2>
<p style="TEXT-ALIGN: justify">After using SSRS, the architecture is just like a small operating system. The Report Manager is the central person who acts as a manager to decide when the reports will be scheduled to run along with maintaining the user profiles on the report server. Also, you can ask the report manager to view or search certain reports. He also helps in site property configuration and folder management in the report server. </p>
<p style="TEXT-ALIGN: justify">There is something known as a Report Server, at which all the reports reside. All other activities pertaining to SSRS is done at report server. I believe it acts like a workstation for the reporting tool. </p>
<p style="TEXT-ALIGN: justify">Report Designer is basically a graphical tool that are hosted within the Microsoft Visual Studio IDE. Report Designer provides a tabbed windows for Data, Layout, and Preview that allow you to design a report interactively. You can add datasets to accommodate a new report design idea, or adjust report layout based on preview results. Also, he provides query builders, an Expression editor, and wizards to step you through the process of creating a simple report. </p>
<p style="TEXT-ALIGN: justify">There is also a Scheduling and Delivery processor who pushes the reports to email inboxes or ftp locations. Like an operating system the adds processes to the queue, the Scheduling and Delivery processor adds processed[executed by the report processor] reports to the queue. </p>
<p style="TEXT-ALIGN: justify">The Report Processor, as the name suggests, executes the reports present in the server. Now that we know the basics of SSRS, lets get starting with our first report. </p>
<h2>Getting Started</h2>
<p style="TEXT-ALIGN: justify">After installing <a href="http://www.codeproject.com/useritems/Start_SSRS.asp" target=_blank>SQL server</a> reporting services on your system, start the Visual studio IDE. </p>
<p style="TEXT-ALIGN: justify">Go to File -&gt; New Project, and you will be shown a prompt with 'New project'. </p>
<p style="TEXT-ALIGN: justify">Select Business Intelligence Projects from the Project Types. As this is our first project, use Report Project Wizard in the templates pane. </p>
<p style="MARGIN-LEFT: 9pt; TEXT-INDENT: -9pt"><img height=293 alt="New Project" src="http://www.codeproject.com/useritems/ReportingServices/image001.jpg" width=357 border=0 v:shapes="_x0000_i1025"></p>
<p style="TEXT-ALIGN: justify">Specify the name of the project as well as the location where the project will be placed. </p>
<p style="TEXT-ALIGN: justify">On click of OK, you will be prompted with a report wizard screen. Click on Next to follow up to the next screen. </p>
<p><img height=406 alt="Screenshot - image003.jpg" src="http://www.codeproject.com/useritems/ReportingServices/image003.jpg" width=640></p>
<p style="TEXT-ALIGN: justify">On the next screen, you will need to create a datasource for the report. This screen is similar to the Connection string creation wizard on creation of a udl file. However, here you just need to click on Edit to specify the server name and the database the will be used from that server. The connection string is automatically created. </p>
<p style="TEXT-ALIGN: justify">This datasource can be made as a shared datasource for multiple reports to access. This can be done by checking in the checkbox present below. </p>
<p style="TEXT-ALIGN: justify">
<p style="TEXT-ALIGN: justify">
<p style="TEXT-ALIGN: justify"><img height=461 alt="Screenshot - image005.jpg" src="http://www.codeproject.com/useritems/ReportingServices/image005.jpg" width=575></p>
<p style="MARGIN-LEFT: -0.75in">
<p style="MARGIN-LEFT: -0.75in">
<p>On click of edit, you will be prompted with the Connection Properties Screen. Here you can add Servername and database name.</p>
<p style="MARGIN-LEFT: 9pt">
<p><img height=348 src="http://www.codeproject.com/useritems/ReportingServices/image007.jpg" width=372 border=0 v:shapes="_x0000_i1027"></p>
<p style="MARGIN-LEFT: -0.75in">
<p style="TEXT-INDENT: 0.75in">Here:</p>
<p style="TEXT-INDENT: 0.75in"><strong>1:select Servername</strong></p>
<p style="TEXT-INDENT: 0.75in"><strong>2:Use SqlServer Authentication</strong></p>
<p style="TEXT-INDENT: 0.75in"><strong>3:select or Enter a Database</strong></p>
<p><strong>4:Test Connection</strong></p>
<p style="MARGIN-LEFT: -0.75in">
<p style="MARGIN-LEFT: -0.75in">
<p><img height=420 src="http://www.codeproject.com/useritems/ReportingServices/image009.jpg" width=516 border=0 v:shapes="_x0000_i1028"></p>
<p style="MARGIN-LEFT: -0.75in">
<p style="MARGIN-LEFT: -0.75in; TEXT-INDENT: 0.75in">Then press ok</p>
<p style="MARGIN-LEFT: -0.75in">
<p><img height=490 src="http://www.codeproject.com/useritems/ReportingServices/image011.jpg" width=449 border=0 v:shapes="_x0000_i1029"></p>
<p style="TEXT-ALIGN: justify">On click of Next, you will be prompted with the Query Builder screen. Here you can add tables, select columns as well as execute the <a href="http://www.codeproject.com/useritems/Start_SSRS.asp" target=_blank>SQL</a> statements therby created.</p>
<p><img height=447 alt="Query Builder" src="http://www.codeproject.com/useritems/ReportingServices/image012.jpg" width=512 border=0 v:shapes="_x0000_i1030"></p>
<p><img height=396 alt="Adding Tables" src="http://www.codeproject.com/useritems/ReportingServices/image014.jpg" width=471 border=0 v:shapes="_x0000_i1031"></p>
<p><img height=447 alt="Running query" src="http://www.codeproject.com/useritems/ReportingServices/image015.jpg" width=512 border=0 v:shapes="_x0000_i1032"></p>
<p style="TEXT-ALIGN: justify">Based on what query suits your report, create the SQL statement and proceed forward. On next click, you will be prompted with the report type screen. You can choose as Tabular or matrix. To make things simpler, use the Tabular format. </p>
<p style="TEXT-ALIGN: justify">
<p><img height=432 alt="Select report type" src="http://www.codeproject.com/useritems/ReportingServices/image017.jpg" width=520 border=0 v:shapes="_x0000_i1033"></p>
<p style="TEXT-ALIGN: justify">On next click, you will come to the table designing screen, wherein you will be prompted to display the fields as Page, Group or Details. The relevant locations where the fields will be placed is shown at the side. </p>
<p><img height=483 alt="Table design" src="http://www.codeproject.com/useritems/ReportingServices/image018.jpg" width=520 border=0 v:shapes="_x0000_i1034"></p>
<p style="TEXT-ALIGN: justify">On next click, you will be prompted with the Table Style prompt, which contains a list to choose. Select any from them . </p>
<p style="TEXT-ALIGN: justify"><img height=384 src="http://www.codeproject.com/useritems/ReportingServices/image020.jpg" width=520 border=0 v:shapes="_x0000_i1035"></p>
<p style="TEXT-ALIGN: justify">n next, you will be prompted with the deployment details screen. Specify the report server name ; normally it is <a href="http://localhost/ReportServer">http://localhost/ReportServer</a>. if you are using another server then you can specify the location as <a href="http://servername/ReportServer">http://servername/ReportServer</a> . Also provide in the deployment folder.</p>
<p style="MARGIN-LEFT: -0.75in; TEXT-ALIGN: justify">
<p style="TEXT-ALIGN: justify"><img height=372 src="http://www.codeproject.com/useritems/ReportingServices/image022.jpg" width=485 border=0 v:shapes="_x0000_i1036"></p>
<p style="MARGIN-LEFT: -0.75in">
<p style="MARGIN-LEFT: -0.75in; TEXT-INDENT: 0.75in; TEXT-ALIGN: justify">Finally, the Report name needs to be entered and voila, you got your first report in place.</p>
<p><img height=420 src="http://www.codeproject.com/useritems/ReportingServices/image024.jpg" width=520 border=0 v:shapes="_x0000_i1037"></p>
<p style="TEXT-ALIGN: justify">nou can preview the report to change the data specs using the 3 tabs from the report designer - as mentioned previously.</p>
<p style="MARGIN-LEFT: -0.75in; TEXT-INDENT: 0.75in; TEXT-ALIGN: justify">
<p style="MARGIN-LEFT: -0.75in; TEXT-ALIGN: justify">
<p style="TEXT-ALIGN: justify"><img height=413 alt="Screenshot - image026.jpg" src="http://www.codeproject.com/useritems/ReportingServices/image026.jpg" width=468></p>
<p style="MARGIN-LEFT: -0.75in">
<p style="MARGIN-LEFT: -0.75in; TEXT-INDENT: 0.75in">Here:</p>
<p style="MARGIN-LEFT: -0.75in; TEXT-INDENT: 0.75in">
<p style="MARGIN-LEFT: -0.75in; TEXT-INDENT: 0.75in">1:select preview </p>
<p style="MARGIN-LEFT: -0.75in; TEXT-INDENT: 0.75in">2:enter credentials here</p>
<p style="MARGIN-LEFT: -0.75in; TEXT-INDENT: 0.75in">3;select view report</p>
<p><img height=320 alt="Screenshot - image028.jpg" src="http://www.codeproject.com/useritems/ReportingServices/image028.jpg" width=424></p>
<p style="MARGIN-LEFT: -1in">
<p style="MARGIN-LEFT: -0.25in; TEXT-INDENT: 0.25in"><img height=384 src="http://www.codeproject.com/useritems/ReportingServices/image030.gif" width=612 border=0 v:shapes="_x0000_i1040"></p>
<p style="MARGIN-LEFT: -1in">
<p><img height=383 src="http://www.codeproject.com/useritems/ReportingServices/image032.gif" width=576 border=0 v:shapes="_x0000_i1041"></p>
<p style="MARGIN-LEFT: -1in">
<p style="MARGIN-LEFT: -1in">
<p style="MARGIN-LEFT: -1in">
<p><img height=432 src="http://www.codeproject.com/useritems/ReportingServices/image034.gif" width=576 border=0 v:shapes="_x0000_i1042"></p>
<p style="MARGIN-LEFT: -1in">
<p style="MARGIN-LEFT: -1in; TEXT-INDENT: 1in">Sorting:</p>
<p style="MARGIN-LEFT: -1in; TEXT-INDENT: 1in">
<p style="MARGIN-LEFT: -1in; TEXT-INDENT: 1in">Right click on this field Productid and select properties .</p>
<p><img height=538 alt="Screenshot - image036.gif" src="http://www.codeproject.com/useritems/ReportingServices/image036.gif" width=600></p>
<p style="MARGIN-LEFT: -1in">
<p style="MARGIN-LEFT: -1in; TEXT-INDENT: 1in">Select the interactivesort tab.</p>
<p style="MARGIN-LEFT: -1in">
<p style="MARGIN-LEFT: -1in">
<p><img height=393 alt="Screenshot - image038.gif" src="http://www.codeproject.com/useritems/ReportingServices/image038.gif" width=440></p>
<p style="MARGIN-LEFT: -1in">
<p style="MARGIN-LEFT: -1in; TEXT-INDENT: 1in">Select the checkbox(add an interactive sort action to this text box) .</p>
<p style="MARGIN-LEFT: -1in">
<p style="MARGIN-LEFT: -1in; TEXT-INDENT: 1in"><img height=545 alt="Screenshot - image040.gif" src="http://www.codeproject.com/useritems/ReportingServices/image040.gif" width=600></p>
<p style="MARGIN-LEFT: -1in">
<p style="MARGIN-LEFT: -1in; TEXT-INDENT: 1in">Then press ok.go to preview.</p>
<p style="MARGIN-LEFT: -1in">
<p style="MARGIN-LEFT: -1in; TEXT-INDENT: 1in"><img height=275 alt="Screenshot - image042.gif" src="http://www.codeproject.com/useritems/ReportingServices/image042.gif" width=597></p>
<p style="MARGIN-LEFT: -1in">
<p style="MARGIN-LEFT: -1in">
<p style="MARGIN-LEFT: -1in">
<p style="MARGIN-LEFT: -1in">
<h2>Use Reports to pass parameters:</h2>
<p style="TEXT-ALIGN: justify">Suppose you need to pass a value from Report 1 to Report 2, then in normal asp.net applications, we either use context or query strings. Lets see how we can do this too.</p>
<p style="TEXT-ALIGN: justify">To demonstrate this, I've created 2 reports Parent.rdl and Child.rdl. The child report has in input parameter named ChildProdID. Select any column from the Parent report as shown below.</p>
<p style="MARGIN-LEFT: -63pt; TEXT-ALIGN: justify">
<p>Right click on this field and you will see the following parameters</p>
<p style="MARGIN-LEFT: -63pt; TEXT-INDENT: 63pt"><img height=336 alt="Screenshot - image044.gif" src="http://www.codeproject.com/useritems/ReportingServices/image044.gif" width=448></p>
<p style="MARGIN-LEFT: -63pt; TEXT-INDENT: 63pt"><img height=376 alt="Right click on textbox" src="http://www.codeproject.com/useritems/ReportingServices/image045.jpg" width=592 border=0 v:shapes="_x0000_i1048"></p>
<p>Select the textbox properties and select the navigation tab.</p>
<p><img height=413 alt=navigation src="http://www.codeproject.com/useritems/ReportingServices/image046.jpg" width=468 border=0 v:shapes="_x0000_i1049"></p>
<p style="TEXT-ALIGN: justify">Select the 'jump to report' tab, and set the report to which you want to jump i.e Child report.</p>
<p><img height=413 alt=navigation src="http://www.codeproject.com/useritems/ReportingServices/image047.jpg" width=468 border=0 v:shapes="_x0000_i1050"></p>
<p style="TEXT-ALIGN: justify">This means that this column will be treated as a hyperlink and on click of this hyperlink, we will jump to Child report. However, we have a parameter that needs to be provided to Child report in order to be executed. Hence, we click on the Parameter button situated at the Navigation tab. On click of this, we get another tab - Parameters.</p>
<p><img height=320 alt=Parameters src="http://www.codeproject.com/useritems/ReportingServices/image048.jpg" width=424 border=0 v:shapes="_x0000_i1051"></p>
<p style="TEXT-ALIGN: justify">In the dropdown we can select the parameter name for that report. For the parameter value, select the field that needs to be evaluated to the parameter name for the report to be executed.</p>
<p><img height=320 alt="Parameter value" src="http://www.codeproject.com/useritems/ReportingServices/image049.jpg" width=424 border=0 v:shapes="_x0000_i1052"></p>
<p>Run the Parent report and click on any of the product ID to navigate to the Child report.</p>
<h3>Manual report creation :</h3>
<p style="TEXT-ALIGN: justify">The Above section, while perhaps overly simplistic, does show you how to get a report up and running with zero code and zero property setting. Obviously, such reports will not meet most development requirements, but do not discount this option as a starting point for more complicated reports. Once you've created a report with the <strong>Report Wizard</strong>, you are free to make any modifications to it. </p>
<p style="TEXT-ALIGN: justify">In this section, we are going to create a more realistic report from scratch, including how to create and use a shared data source object, stored procedures, and how to format your report, set report properties and use report parameters. </p>
<h4>Creating a shared data source </h4>
<p style="TEXT-ALIGN: justify">Before we start the report, we are going to build a shared data source i.e. a data source that is common to, and can be used by, all of the reports on a reporting server. While each report can contain its own connection information, it is good practice to use shared data sources, as it will save you a lot time and headaches. This way, you only have to set the connection information once. For example, let's say your company has Development, Test and Production environments. If you put the connection information into each report, you will have to change it each time when you publish to Development, Test and Production. If you use a shared data source, you still have to set up a data source object for each of three environments, but you can simply publish the report to each environment, and they will automatically use the connection information associated with that environment. </p>
<p style="TEXT-ALIGN: justify">From the menu select <strong>Project &gt; Add New Item &gt; Select Data Source</strong>. On the <strong>General</strong> tab, call the data source "ReportsDB". Leave the Type as <strong>Microsoft SQL Server</strong>. Click the <strong>Edit</strong> button on the right, and enter the connection information for Reporting Demo, as before. Click <strong>OK</strong> on the <strong>Shared Data Source</strong> screen and the data source is done.</p>
<h4>Add a new report </h4>
<p style="TEXT-ALIGN: justify">From the menu select <strong>Project &gt; Add New Item</strong>. Select <strong>Report</strong> and name it "FirstReportMan.rdl". A new report will be added to the project, and the <strong>Report Designer</strong> will open at the <strong>Data</strong> tab. At this point, let's take a closer look at the <strong>Report Designer</strong> tool. At the top of the Report Designer window are three tabs: <strong>Data</strong>, <strong>Layout</strong> and <strong>Preview</strong>. The <strong>Data</strong> tab is used to build data sources for your report. The <strong>Layout</strong> tab is the physical report designer where you set up the header, the footer and the data presentation of the report. The <strong>Preview</strong> tab allows you to actually run the report from Visual Studio 2005, without having to publish it to a report server first. If your report takes parameters, the <strong>Preview</strong> tab will ask you to fill them out before it runs the report.</p>
<p style="TEXT-ALIGN: justify">The first thing we need to do is get data into our report. At the top of the <strong>Data</strong> tab choose <strong>&lt;New Dataset&#8230;&gt;</strong> from the dropdown list:</p>
<p><img height=483 alt="Screenshot - image002.jpg" src="http://www.codeproject.com/useritems/ReportingServices/image002.jpg" width=520></p>
<p>The <strong>Dataset</strong> dialog opens:</p>
<p><img height=463 alt="Screenshot - image004.jpg" src="http://www.codeproject.com/useritems/ReportingServices/image004.jpg" width=576></p>
<p style="TEXT-ALIGN: justify">Name the dataset "ReportData", and select the <strong>ReportsDB</strong> data source from the dropdown. Select <strong>StoredProcedure</strong> as the command type, and enter "spr_CustomerSelectAll" in the query string box. Click <strong>OK</strong> to close the dialog.</p>
<p style="TEXT-ALIGN: justify">Test the dataset by clicking on the big red exclamation point at the top of the report designer. This executes the query and displays the results. You can repeat these steps if you wish to add multiple datasets to your report.</p>
<h4>Setting up the report display </h4>
<p style="TEXT-ALIGN: justify">Next, switch to the <strong>Layout</strong> tab. This is where you actually build the report display. Start by dragging a table from the Toolbox, onto the Body section of the report. By default, the table shows a header row at the top, a detail row in the middle and a footer row at the bottom. You can add additional columns to the table by right-clicking on one of the columns and selecting one of the two <strong>Insert Column</strong> options.</p>
<p>Click on the <strong>Datasets</strong> tab under Toolbox on the left-hand side of the Visual Studio environment. You should see the <strong>ReportData</strong> dataset. Expand it, select <strong>FirstName</strong> and drag it to the first cell of the body row of the table. This will display the First Name field in the first column. Now put the <strong>LastName</strong> in the second column, and the <strong>CustomerStatus</strong> in the third:</p>
<p><img height=490 alt="Screenshot - image006.jpg" src="http://www.codeproject.com/useritems/ReportingServices/image006.jpg" width=521></p>
<p style="TEXT-ALIGN: justify">Note that, when you drag the column <strong>FirstName</strong> into the body row of the table, SSRS make a guess as to what to call the row. It calls it "First Name". You can click on the <strong>Preview</strong> tab to view the report.</p>
<h4>Adding formatting </h4>
<p style="TEXT-ALIGN: justify">Let's add the <strong>DateOfBirth</strong> column to the table. You can expand and shrink the size of the columns by highlighting and dragging:</p>
<p><img height=428 alt="Screenshot - image008.jpg" src="http://www.codeproject.com/useritems/ReportingServices/image008.jpg" width=471></p>
<p style="TEXT-ALIGN: justify">If you wish to get rid of the footer row of the table and then click on any field in the table. You will see a grey box surround the table. Right-click on the icon at the beginning of the body row and then click the <strong>Table Footer</strong> option to deselect it.</p>
<p style="TEXT-ALIGN: justify">The table header is next. To format all the cells in the header in the same way, click and drag over all the cells to select them. Open the <strong>Properties</strong> window and set background color, font, and so on.</p>
<p><img height=483 alt="Screenshot - image010.jpg" src="http://www.codeproject.com/useritems/ReportingServices/image010.jpg" width=520></p>
<p style="TEXT-ALIGN: justify">Note, however, that if you wish to change the justification of the text or the size, then you do so using the main menu at the top, not via the properties window. Again, you can click on the <strong>Preview</strong> tab to view the report.</p>
<h4>Add a report header </h4>
<p style="TEXT-ALIGN: justify">The table already has a header, but the report can also have a header and footer. Report headers and footers appear on every page of the report. Put the <strong>Report Designer</strong> in <strong>Layout</strong> mode and select <strong>Report &gt; Page Header</strong> from the menu. A new band labeled <strong>Page Header</strong> appears on the report above the body. Drag a text box onto the header and click directly on it. Type "My First Report", not in the <strong>Properties</strong> window, but right on the control.</p>
<p><img height=487 alt="Screenshot - image013.jpg" src="http://www.codeproject.com/useritems/ReportingServices/image013.jpg" width=521></p>
<p style="TEXT-ALIGN: justify">To adjust the text style and size of your heading, highlight the text box and use the option from the top menu.</p>
<h4>Formatting </h4>
<p style="TEXT-ALIGN: justify">Each field can have formatting. Let's deal with that ugly <strong>Date of Birth</strong> field. The time information is superfluous, so let's format the date properly. Right-click on the cell that contains the date of birth, and choose <strong>Properties</strong>. Next, select the <strong>Format</strong> tab.</p>
<p><img height=432 alt="Screenshot - image015.jpg" src="http://www.codeproject.com/useritems/ReportingServices/image015.jpg" width=575></p>
<p style="TEXT-ALIGN: justify">Click on the second button (labeled <strong>"&#8230;"</strong>) to the right of the <strong>Format code</strong> field. When the dialog opens, use the standard options. Select <strong>Date</strong> in the list on the left, then choose </p>
<p style="TEXT-ALIGN: justify">
<p style="TEXT-ALIGN: justify">
<p style="TEXT-ALIGN: justify">the sample date format you want on the right. Click <strong>OK</strong> to close the dialog.</p>
<p style="TEXT-ALIGN: justify">
<p style="TEXT-ALIGN: justify">
<p style="TEXT-ALIGN: justify">Click <strong>OK</strong> to close the <strong>Properties</strong> window and then click on the <strong>Preview</strong> tab to view the report.</p>
<p style="TEXT-ALIGN: justify"><img height=430 alt="Screenshot - image017.jpg" src="http://www.codeproject.com/useritems/ReportingServices/image017.jpg" width=640></p>
<h4>Setting report properties </h4>
<p style="TEXT-ALIGN: justify">To access the report properties, you need to be on the <strong>Layout</strong> tab of the <strong>Report Designer</strong>. When you click on this tab, a new menu item, <strong>Report</strong>, activates. This menu gives you options for turning on and off the report header and footer sections (as we have seen), adding embedded images, setting report properties, and setting report parameters.</p>
<p style="TEXT-ALIGN: justify">Setting up the report print settings is not intuitive, compared to other products. In the report <strong>Layout</strong> tab you see your report with a ruler across the top. That ruler is set up in inches. A standard sheet of paper is 8.5 x 11 inches. The default setting in SSRS is to have a 1-inch margin all the way around the content area. So, at 8.5 inches wide with a 1-inch margin on the left and another on the right, you have 6.5 inches for content. Any more, and the content beyond the 6.5 inches will spill over onto a second sheet of paper when printed. It will <strong>not</strong> automatically shift to Landscape.</p>
<p style="TEXT-ALIGN: justify">To get Landscape reports, you have to make the proper report settings. Navigate to the <strong>Layout</strong> tab of the <strong>Report Designer</strong>. From the <strong>Report</strong> menu select <strong>Report Properties</strong>. Switch to the <strong>Layout</strong> tab of the dialog box. To switch to Landscape printing, you need to change <strong>Page width</strong> to 11in and the <strong>Page height</strong> to 8.5in. </p>
<p><img height=419 alt="Screenshot - image019.jpg" src="http://www.codeproject.com/useritems/ReportingServices/image019.jpg" width=640></p>
<p>On the same <strong>Layout</strong> tab, you can also get up your report to display the data in multiple columns, and you can control the margins. By default, all the margins are set at 1 inch. Remember, if your report width, plus the right and left margins, is greater than the width of the printer, you will get spill-over when you print out your report.</p>
<h4>Using parameters </h4>
<p>There are two ways to add parameters to your reports. The first is to use parameters in the queries in your data sources. The second is to set up parameters through the <strong>Report Parameters</strong> dialog box. We will do both.</p>
<h5>Query parameters </h5>
<p>First, we will set up parameters using a data source query. Navigate to the <strong>Data</strong> tab, and click the <strong>"&#8230;"</strong> button right next the <strong>Dataset</strong> dropdown box. The <strong>Dataset</strong> dialog box opens and allows you to edit the query for the dataset. Change the Query string from "spr_CustomerSelectAll" to "spr_CustomerSelectByState". </p>
<p>Click <strong>OK</strong> and then run the query by clicking the red exclamation point (!) on the <strong>Data</strong> tab toolbar. You will be prompted to enter a parameter value for StateCD (the State code). Enter "CA" and click <strong>OK</strong>. The query should return all the customers that live in California.</p>
<p style="TEXT-ALIGN: justify">Switch to the <strong>Preview</strong> tab. Instead of the report just running, there should be a place for you to enter a value for the "StateCD" and run the report. Enter "CA" and click the <strong>View Report</strong> button. You should see your report filtered by state.</p>
<p style="TEXT-ALIGN: justify">To edit the parameters, or to add new ones, switch to the <strong>Layout</strong> tab of the <strong>Report Designer</strong> and open the <strong>Report Parameters</strong> dialog from the <strong>Report</strong> menu. First, we are going to make the "State code" prompt a little more friendly. Select <strong>StateCD</strong> in the Parameters list box then, in the Parameters Properties box, change the prompt to read "State". In the <strong>Available values</strong> section enter "California" and "CA" on the first line. Enter "Louisiana" and "LA" on the second line.</p>
<p><img height=422 alt="Screenshot - image021.jpg" src="http://www.codeproject.com/useritems/ReportingServices/image021.jpg" width=467></p>
<p style="TEXT-ALIGN: justify">This will make the prompt for "State value" into a dropdown. You can also build additional datasets into your report, and use the values in those datasets as criteria for dropdowns.</p>
<h5>Report parameters </h5>
<p style="TEXT-ALIGN: justify">Now let's add a parameter that is not used in a query. Click the <strong>Add</strong> button in the <strong>Report Parameters</strong> dialog from the <strong>Report</strong> menu. Give the new parameter the name "ReportTitle". Its Data type should be <strong>String</strong>. Set the <strong>Prompt</strong> to "Report Title". Click <strong>OK</strong> and close the dialog box.</p>
<p style="TEXT-ALIGN: justify">Drag a new text box onto the report header area. Right-click on it and choose the <strong>Expression</strong> option. In the <strong>Edit Expression</strong> dialog select <strong>Parameters</strong>. Double-click on the <strong>ReportTitle</strong> parameter. This text box will now display the value you pass to the <strong>Report Title</strong> parameter.</p>
<p><img height=273 alt="Screenshot - image023.jpg" src="http://www.codeproject.com/useritems/ReportingServices/image023.jpg" width=575></p>
<p>Switch to the <strong>Preview</strong> tab and try it out. </p>
<h3>Publishing your reports </h3>
<p style="TEXT-ALIGN: justify">Up to now, you have been running your reports in the Visual Studio 2005 environment but, to make them useful, you must publish them to a report server. The easiest way to do this is to have Visual Studio publish your reports. </p>
<p style="TEXT-ALIGN: justify">Start by right-clicking on <strong>Project</strong> in the <strong>Project Explorer</strong> and choose <strong>Properties</strong>. </p>
<p><img height=376 alt="Screenshot - image025.jpg" src="http://www.codeproject.com/useritems/ReportingServices/image025.jpg" width=592></p>
<p style="TEXT-ALIGN: justify">Set <strong>TargetServerURL</strong> to the URL of your report server. Use the <strong>TargetReportFolder</strong> property to set up a folder for your reports. If the folder does not exist, the Publisher will create it for you. The other key thing to pay attention to here is the <strong>OverwriteDataSources</strong> property. When this property is set to "True", it will automatically copy over all your data source objects when you publish. When set to "False", it will copy any new data source objects, but it will not overwrite existing ones. This is important when dealing with development, test and production servers. You can publish a set of data source objects to each server, pointed at the correct database, and never have to worry about what database your reports are hitting in each environment.</p>
<p style="TEXT-ALIGN: justify">From the <strong>Build</strong> menu select <strong>Deploy Solution</strong>. This will publish the project to the selected folder on your report server. You can also deploy individual reports by right-clicking on the file in the <strong>Solution explorer</strong> and selecting <strong>Deploy</strong>.</p>
<p style="TEXT-ALIGN: justify">Once your report has been published, you can access and run it on your server through the browser at <strong>http://&lt;servername(STPPC1742)&gt;/&lt;reportservername(myreport)&gt;</strong>. From the <strong>Home</strong> page, you should be able to find the folder you published to, with the reports in it. Select a report to run. At the top of the page you can enter any values for report parameters, and then run the report. From here, you can also print or export the report. </p>
<p><strong>Subreports :</strong><strong></strong></p>
<p style="TEXT-ALIGN: justify">A subreport is a report that is embedded into another report. Subreports can take parameters and execute their own datasets. A key aspect to note is that a subreport in SSRS is actually just another report (unlike some reporting tools, where a subreport is a special construct). In fact, in SSRS you can execute a subreport on its own. </p>
<p style="TEXT-ALIGN: justify">To add a subreport to a report, you simply drag a subreport control onto the report and tell it which report to display. If the subreport requires parameters, you have to tell the main report which value to pass to the subreport. It's actually very simple.</p>
<p style="MARGIN-BOTTOM: 12pt; TEXT-ALIGN: justify">Let's add a new report to the project and call it <strong>MainReport.rdl</strong>. Create a new dataset using the shared datasource and the query:</p>
<pre style="TEXT-ALIGN: justify">SELECT CustomerID, FirstName, LastName FROM Customer</pre>
<p style="TEXT-ALIGN: justify">Switch to the <strong>Layout</strong> tab. Drag a table on the report detail area. Set up the first column to display the customer's first name (by dragging that column from the Datasets tab into the Detail row) and set up the second column to display the customer's last name. Label the third column 'Address'. Preview the report, just to be sure it works.</p>
<p style="TEXT-ALIGN: justify">Create another report, and call this one <strong>MySubReport.rdl</strong>. This time, create a dataset that uses the shared data source, and use the following query text:</p>
<p style="TEXT-ALIGN: justify">SELECT Address, City, State, ZipCode</p>
<p style="TEXT-ALIGN: justify">FROM Customer</p>
<p>WHERE (CustomerID = @CustomerID)</p>
<p style="TEXT-ALIGN: justify">In the <strong>Layout</strong> tab, use text boxes to create the address layout, as shown in figure 5. You can simply drag the text boxes onto the screen by clicking on the field in datasets tab and dragging it onto design surface. You will also note that when you do this, the expression used to set the value property for the textbox uses the <strong>First()</strong> function. This function will use the value from the first row returned by the dataset. All other rows returned are ignored.</p>
<p><img height=413 alt="Screenshot - image027.jpg" src="http://www.codeproject.com/useritems/ReportingServices/image027.jpg" width=468></p>
<p style="TEXT-ALIGN: justify">Now preview the report and use '100' for the <strong>CustomerID</strong> parameter.</p>
<p style="TEXT-ALIGN: justify">Let's jump back to the <strong>MainReport.rdl</strong>. To embed the subreport, drag a <strong>SubReport</strong> control into the detail cell for the column you labeled 'Address'. Right-click on the <strong>SubReport</strong> control and select <strong>Properties</strong>. In the <strong>Properties</strong> dialog choose <strong>MySubReport</strong> from the subreport dropdown.</p>
<p><img height=320 alt="Screenshot - image029.jpg" src="http://www.codeproject.com/useritems/ReportingServices/image029.jpg" width=424></p>
<p style="TEXT-ALIGN: justify">Next, switch to the <strong>Parameters</strong> tab. This is where you connect your subreport to the main report. You do this by indicating which value from the main report is to be passed to the subreport to fulfill its parameter requirements.</p>
<p style="TEXT-ALIGN: justify">In the <strong>Parameter Name</strong> column choose <strong>CustomerID</strong> and in the <strong>Parameter Value</strong> column choose =Fields!CustomerID.Value. This will wire up the subreport to whichever customer is being displayed in the row of the table. </p>
<p><code><img height=497 alt="Screenshot - image031.gif" src="http://www.codeproject.com/useritems/ReportingServices/image031.gif" width=600></code></p>
<p>Click <strong>OK</strong> to close the dialog, and then preview the main report.When the report runs, it looks like this:</p>
<p style="MARGIN-LEFT: -1in; TEXT-INDENT: 1in"><img height=487 alt="Screenshot - image033.gif" src="http://www.codeproject.com/useritems/ReportingServices/image033.gif" width=600></p>
<p><strong>The Matrix :</strong></p>
<p><strong>Create the sample report and choose the report type as matrix see below..</strong></p>
<p><strong><img height=487 alt="Screenshot - image035.gif" src="http://www.codeproject.com/useritems/ReportingServices/image035.gif" width=600></strong></p>
<p><strong>And click next button..</strong></p>
<p><strong><img height=381 alt="Screenshot - image037.jpg" src="http://www.codeproject.com/useritems/ReportingServices/image037.jpg" width=334></strong></p>
<p style="TEXT-ALIGN: justify"><strong>From above window select page,coloumns, rows and details from </strong><strong>available fields.ad enable drill down also(Optional).</strong></p>
<p style="TEXT-ALIGN: justify"><strong></strong></p>
<p style="TEXT-ALIGN: justify">The drill down functionality in SSRS allows you to have areas of your report that can expand and collapse, much like a tree view.</p>
<p><strong><img height=472 alt="Screenshot - image039.gif" src="http://www.codeproject.com/useritems/ReportingServices/image039.gif" width=600></strong><strong></strong></p>
<p><strong>Click on next button fallowing window will be opened.</strong></p>
<p><strong><img height=399 alt="Screenshot - image041.gif" src="http://www.codeproject.com/useritems/ReportingServices/image041.gif" width=600></strong></p>
<p>Click <strong>finish</strong> to close the dialog, and then preview the main report.When the report runs, it looks like this:</p>
<p><img height=336 alt="Screenshot - image043.gif" src="http://www.codeproject.com/useritems/ReportingServices/image043.gif" width=448></p>
<p><strong>you can see the customer Company name by using the tree-style +/- controls</strong>.</p>
<p><img height=324 alt="Screenshot - image045.jpg" src="http://www.codeproject.com/useritems/ReportingServices/image045.jpg" width=576></p>
<p><strong>Creating Charts:</strong><strong></strong></p>
<p style="TEXT-ALIGN: justify">SQL Server 2005 Reporting Services includes a basic chart control that handles most situations quite nicely, and third-party chart controls are available as well. The chart controls let you set categories for the <em>x</em> axis and data points for the <em>y</em> axis, and you can add one or more series to the chart.</p>
<p style="TEXT-ALIGN: justify">To create a chart, you can drag a chart control onto the report designer in the Layout tab. The chart control automatically goes into "set me up" mode, letting you drag the DataSet's fields into the category, data, and series areas. The fields you drag into the category area are used for the <em>x</em> axis while those dragged to the data area are used as the data points that define the bars, pie chart, or lines .You need at least one field in each of these areas to create a useful chart, though you can add more if you want.</p>
<p><strong><img height=468 alt="Screenshot - image047.jpg" src="http://www.codeproject.com/useritems/ReportingServices/image047.jpg" width=519></strong></p>
<p style="TEXT-ALIGN: justify"><strong>Rightclick on chart control chart properties window will get the chartproperties window.</strong></p>
<p style="TEXT-ALIGN: justify"><strong>By using this we can edit the chat properties.</strong></p>
<p style="TEXT-ALIGN: justify"><strong><img height=490 alt="Screenshot - image049.jpg" src="http://www.codeproject.com/useritems/ReportingServices/image049.jpg" width=518></strong><strong></strong></p>
<p>and then preview the report.When the report runs, it looks like this:</p>
<p style="MARGIN-LEFT: -1in">
<ul class=download>
    <li><a href="http://www.codeproject.com/useritems/ReportingServices/SSRS_1.zip">Download SSRS_1.zip - 1,784.1 KB</a> </li>
</ul>
<!-- Article Ends -->
<script src="/script/togglePre.js" type=text/javascript></script>
<img src ="http://www.cnitblog.com/MartinYao/aggbug/32429.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/MartinYao/" target="_blank">玄铁剑</a> 2007-08-25 22:47 <a href="http://www.cnitblog.com/MartinYao/articles/32429.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Microsoft Reporting Services in Action</title><link>http://www.cnitblog.com/MartinYao/articles/32428.html</link><dc:creator>玄铁剑</dc:creator><author>玄铁剑</author><pubDate>Sat, 25 Aug 2007 14:46:00 GMT</pubDate><guid>http://www.cnitblog.com/MartinYao/articles/32428.html</guid><wfw:comment>http://www.cnitblog.com/MartinYao/comments/32428.html</wfw:comment><comments>http://www.cnitblog.com/MartinYao/articles/32428.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/MartinYao/comments/commentRss/32428.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/MartinYao/services/trackbacks/32428.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Introducing Microsoft Reporting Services    1.1 What is RS?    1.2 RS at a glance    1.3 RS architecture    1.4 Understanding Report Processing    1.5 Delivering reports    1.6 What is t...&nbsp;&nbsp;<a href='http://www.cnitblog.com/MartinYao/articles/32428.html'>阅读全文</a><img src ="http://www.cnitblog.com/MartinYao/aggbug/32428.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/MartinYao/" target="_blank">玄铁剑</a> 2007-08-25 22:46 <a href="http://www.cnitblog.com/MartinYao/articles/32428.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Excel導出問題 </title><link>http://www.cnitblog.com/MartinYao/articles/28614.html</link><dc:creator>玄铁剑</dc:creator><author>玄铁剑</author><pubDate>Sun, 17 Jun 2007 05:02:00 GMT</pubDate><guid>http://www.cnitblog.com/MartinYao/articles/28614.html</guid><wfw:comment>http://www.cnitblog.com/MartinYao/comments/28614.html</wfw:comment><comments>http://www.cnitblog.com/MartinYao/articles/28614.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/MartinYao/comments/commentRss/28614.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/MartinYao/services/trackbacks/28614.html</trackback:ping><description><![CDATA[<p>权限问题:&nbsp;&nbsp; <br>&nbsp; 如果是Window2003&nbsp;&nbsp; -&gt;控制面版&nbsp;&nbsp; -&gt;&nbsp;&nbsp; 管理工具&nbsp;&nbsp; -&gt;&nbsp;&nbsp; 组件服务&nbsp;&nbsp; -&gt;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 打开树级目录找到子目录DCOM配置&nbsp;&nbsp; -&gt;&nbsp;&nbsp; Microsoft&nbsp;&nbsp; Excel&nbsp;&nbsp; 应用程序&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;&nbsp;&nbsp; 右击选&#8220;属性&#8221;&nbsp;&nbsp; -&gt;&nbsp;&nbsp; 在弹出对话窗口中选&#8220;安全&#8221;选项卡-&gt;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;&nbsp;&nbsp; 将启动和激活权限设为自定义-&gt;点击编辑按钮-&gt;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;在新窗口中将Everyone用户加入,选中复选框"启动权限",给予启动权限&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <br>&nbsp; 如果是WindowXP&nbsp;&nbsp; -&gt;控制面版&nbsp;&nbsp; -&gt;&nbsp;&nbsp; 管理工具&nbsp;&nbsp; -&gt;&nbsp;&nbsp; 组件服务(繁体为"元件服务")&nbsp;&nbsp; -&gt;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 打开树级目录找到子目录DCOM配置&nbsp;&nbsp; -&gt;&nbsp;&nbsp; Microsoft&nbsp;&nbsp; Excel&nbsp;&nbsp; 应用程序&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;&nbsp;&nbsp; 右击选&#8220;属性&#8221;&nbsp;&nbsp; -&gt;&nbsp;&nbsp; 在弹出对话窗口中选&#8220;安全&#8221;选项卡-&gt;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;&nbsp;&nbsp; 将启动和激活权限设为自定义-&gt;点击编辑按钮-&gt;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;在新窗口中将Everyone用户加入,选中复选框"远程启动",给予远程启动权限&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <br>&nbsp; 其它操作系统应该类似. </p>
<p>&nbsp;</p>
<img src ="http://www.cnitblog.com/MartinYao/aggbug/28614.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/MartinYao/" target="_blank">玄铁剑</a> 2007-06-17 13:02 <a href="http://www.cnitblog.com/MartinYao/articles/28614.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ASP.NET Server-Side Charting with OWC11</title><link>http://www.cnitblog.com/MartinYao/articles/24000.html</link><dc:creator>玄铁剑</dc:creator><author>玄铁剑</author><pubDate>Tue, 13 Mar 2007 14:49:00 GMT</pubDate><guid>http://www.cnitblog.com/MartinYao/articles/24000.html</guid><wfw:comment>http://www.cnitblog.com/MartinYao/comments/24000.html</wfw:comment><comments>http://www.cnitblog.com/MartinYao/articles/24000.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/MartinYao/comments/commentRss/24000.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/MartinYao/services/trackbacks/24000.html</trackback:ping><description><![CDATA[
		<ul class="download">
				<li>
						<a href="http://www.codeproject.com/aspnet/owc11article/WebGraphApp_OWC11_Sample.zip">Download source - 211 Kb</a>
				</li>
		</ul>
		<h2>Introduction</h2>
		<p nd="1">In Client-Server applications, like public commercial websites and private corporate intranet sites, having graphical reports is a common requirement. Typically, when we have some data projecting the periodical sales figures or the profit and loss margins, it is an obvious use case scenario of having graphical reports summarizing the data over a period. </p>
		<p nd="2">In such scenarios, if it is a windows application we can have some graphics libraries installed on every machine to generate the charts. Where as in web applications the type of browser and the version being used defines the client capability. Here we will have two options to go for:</p>
		<ul type="disc">
				<li nd="3">Client-Side Charting &amp; 
</li>
				<li nd="4">Server-Side Charting </li>
		</ul>
		<p nd="5">In client side charting, the client should have a charting engine installed in the machine and a supporting browser. This will help in achieving the client side interactive charting as well as Windows functionality within the browsers. But on the downside, will have complexities in the distribution and setup of the client-side software. And usually license costs per client will increase.</p>
		<p nd="6">Where as in Server-side charting, only the server needs to have the charting engine installed and the charts can be dynamically generated and streamlined to the client in the form of gif or jpeg. Which is cost effective and any normal browser is sufficient at the client-side. But on the downside, Interactive charting cannot be provided and any change in data or refresh at the client leads to a request to the server and the re-generation of the chart.</p>
		<p nd="7">This article focuses on the Server side charting in ASP.NET environment. And it also emphasizes on the OWC11 object model and different options for binding data to the chart.</p>
		<h2>Why OWC?</h2>
		<p nd="8">In ASP.Net Environment we have several ways for generating charts. Some of them are as follows:</p>
		<ul>
				<li nd="9">Using the ASP.Net built-in graphics library (System.Drawing). 
</li>
				<li nd="10">Using the existing charting engines like, 
<ul><li nd="11">MS-Excel Charting engine 
</li><li nd="12">Crystal Reports Charting engine 
</li><li nd="13">Dundas Chart Control for ASP.Net 
</li><li nd="14">Mycos Charts .Net Web Forms Edition 
</li><li nd="15">netCharting etc., </li></ul></li>
		</ul>
		<p nd="16">Using the ASP.NET built-in graphics library is the most tedious task and demands a lot of design and implementation effort to be kept in explicitly drawing charts and developing required components.</p>
		<p nd="17">Coming to the existing charting engines, most of them are pretty expensive and will have a foreign look. Out of these, MS Excel Charting engine is the most widely used and one of the most powerful engines available in the market. </p>
		<p nd="18">As MS Excel is a widely used application, Microsoft came up with a new idea of providing office like functionality on the web. And this is achieved thru “OWC – Office Web Components” which is the center for our current article. </p>
		<p>
				<img height="289" src="http://www.codeproject.com/aspnet/owc11article/image001.jpg" width="575" />
		</p>
		<h2>History</h2>
		<p nd="19">The first version of OWC called OWC9 came with MS-Excel 2000 and MS-Front page 2000. OWC9 came with minimum required charting features that can be used by any web application. Later the next version OWC10 or OWCXP came with MS-Office XP. Though there is no much difference in OWC9 and OWC10, the second version holds some interesting functions for optimizing the performance while generating and saving the charts and some new properties for a better look of charts. And now the latest version OWC11 came with MS-Office 2003. This OWC11 has got some really interesting features like XML support etc.,</p>
		<h2>Licensing Issues</h2>
		<p nd="20">Regarding the licensing issues of OWC11, we should have license of either MS-Excel 2003 or Front Page 2003. And also when we use OWC11 for client side charting the license is required on both the server and client. Where as, when we use OWC11 for server-side charting, license is required only on the server. </p>
		<h2>How to Use OWC?</h2>
		<p nd="21">OWC is a COM component holding four ActiveX controls.</p>
		<ul>
				<li nd="22">Spreadsheet control 
</li>
				<li nd="23">Chartspace control 
</li>
				<li nd="24">Pivottable control &amp; 
</li>
				<li nd="25">Datasource control </li>
		</ul>
		<p nd="26">OWC can be used as either client-side technology by installing it in the client system or as server-side technology by installing only in the server. Coming to the server-side, the core concentration will be on programmatic usage of OWC for generating charts dynamically. Using the OWC Chartspace component, a chart can be generated in the memory of server and can be later streamlined to the client browser as gif or jpeg as a Response to an HTTP Request. So, using OWC11 at server-side only the charting functions, which are of main interest.</p>
		<p nd="27">Coming to ASP.Net, an OWC11 Interop assembly is required that acts as an RCW (Runtime Callable Wrapper). This Interop assembly can be generated in two ways:</p>
		<ol type="1">
				<li nd="28">By using the .Net Command Line Utility “Tlbimp”. </li>
		</ol>
		<p>
				<i>Tlbimp owc11.dll /out:Interop.owc11.dll</i>
		</p>
		<ol type="1" start="2">
				<li nd="29">By using the MS Visual Studio. Net. The .Net IDE creates the wrapper directly when we select the OWC11 COM Component as one of the references for our ASP.Net web application. </li>
		</ol>
		<p nd="30">Now we have two steps for generating a chart.</p>
		<p nd="31">First step involves declaring an object of <code nd="32">owc11.Chartspace</code> and adding a chart object to the <code nd="33">chartspace.charts</code> collection object. Later we can add as many data series as required to the <code nd="34">seriescollection</code> object of the chart object. Last but not least we can do some formatting to the Axes, Borders and Interior of the chart as well as to the chartspace and so on.</p>
		<p nd="35">Second step involves whether saving this chart in a physical Image files like gif or directly streamlining the chart to an Image Control. Saving the chart to a gif file can be done by exporting the <code nd="36">chartspace</code> object to the required file at required resolution. </p>
		<p nd="37">Where as, Streamlining requires a bit of different setting. We have to keep the whole code that generates the chart inside the code-behind of an aspx page that contains no HTML content. Where in, this aspx page can be given as an Image source to an Image control on any other page. Inside this aspx page, after generating the chart, we have to use the <code nd="38">GetPicture</code> Method of the Chartspace to push the chart to the Image control directly. </p>
		<p nd="39">Thus, we can have the charts dynamically generated on the server and pushed to the client. This approach will make the coding part easier, more formatting options and faster generation of the charts.</p>
		<h2>OWC11 Charting Engine Object Model</h2>
		<p nd="40">In OWC11, the charting engine is exposed out as a Chartspace ActiveX Control. This is something similar to a chart control that comes along with visual studio. </p>
		<p nd="41">A simplified <code nd="42">Chartspace</code> object model will be as follows:</p>
		<h3>
				<img height="560" src="http://www.codeproject.com/aspnet/owc11article/image002.jpg" width="264" />
		</h3>
		<h2>Download Details</h2>
		<p nd="43">The OWC11 is a free download available in the Microsoft website at the below link.</p>
		<ul>
				<li>
						<a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=7287252c-402e-4f72-97a5-e0fd290d4b76&amp;displaylang=en">http://www.microsoft.com/downloads/details.aspx?FamilyID=7287252c-402e-4f72-97a5-e0fd290d4b76&amp;displaylang=en</a>
				</li>
		</ul>
		<!-- Article Ends -->
		<script src="/script/togglePre.js" type="text/javascript">
		</script>
<img src ="http://www.cnitblog.com/MartinYao/aggbug/24000.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/MartinYao/" target="_blank">玄铁剑</a> 2007-03-13 22:49 <a href="http://www.cnitblog.com/MartinYao/articles/24000.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>