Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
DotNet
acad.assignment.mngr
academic
adonet
aspnet
aspnet.announcements
aspnet.build.controls
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
clr
compactframework
component_services
datatools
distributed_apps
drawing
faqs
framework
framework.wmi
general
internationalization
interop
languages.csharp
languages.jscript
languages.vb
languages.vb.controls
languages.vb.data
languages.vb.upgrade
languages.vc
languages.vc.libraries
myservices
odbcnet
performance
remoting
scripting
sdk
security
setup
vjsharp
vsa
webservi.enhancements
webservices
windowsforms
windowsforms.controls
winforms.databinding
winforms.designtime
xml
  
 
date: Wed, 23 Jul 2008 00:44:19 +0300,    group: microsoft.public.dotnet.languages.csharp        back       


Microsoft Report Viewer with SqlConnection   
anyone has a code sample to connect the Microsoft Report Viewer Control 
using Microsoft SQL Server stored procedure?
date: Wed, 23 Jul 2008 00:44:19 +0300   author:   Jassim Rahma

Re: Microsoft Report Viewer with SqlConnection   
Hi Jassim,

This can be a big question, and your question is a bit vague. I'm assuming 
that you have a rdl file already and that has a datasource defined so the 
report can process the results. Actually, the fact that it's a stored proc 
is irrelevant since the report viewer doesn't query for data, you have to 
get the data yourself and then assign it to the report.

First off you need to know the datasource name required. You can find these 
out easily enough by.iterating over the DataSources collection.

Now assuming you have an aspx file with a ReportViewer web control on it 
called ReportViewer1, and an RDL(C) Report File already loaded in it, this 
code will get you the datasource names contained.

// code block 1
List<string> dataSourceNames = new List<string>();
foreach(ReportDataSource rds in ReportViewer1.LocalReport.DataSources)
{
    dataSourceNames.Add(rds.Name);
}

now you can assign to the data sources by index or name. so if your report 
has a single datasource called DataSet1_DataTable1 which has the columns 
defined, you can simply do

DataTable data = YourMethodToLoadDataFromYourStoredProc();
// line 2
ReportViewer1.LocalReport.DataSources["DataSet1_DataTable1"].Value = data;
ReportViewer1.Refresh();

or you can avoid looking through the defined datasources first and simply 
assign to ReportViewer1.LocalReport.DataSources[0] - although this will be 
error prone.

now if you don't know the stored proc or query to call in advance, but it's 
specified in the report, things are trickier because the ReportViewer API 
doesn't appear to expose this information. You will need to parse the XML 
from the RDL file and find the DataSets/DataSet/Query node for each DataSet 
in the report. Among other things, this node has a child node CommandText, 
the InnerText of which will be the query - either a SQL command or the 
stored proc call.

If the query expects parameters it's more difficualt again. To obtain this 
information you will need to parse the Query/QueryParameters node from the 
XML and resolve the parameters yourself. Note that the report viewer doesn't 
generate any UI for user input of report parameters so if you want this to 
be automatic, you'll need to write some code to generate the UI dynamically 
yourself.

if you need some help with parsing the XML let me know. it's easy enough, 
but it's a little beyond beginner level if you've not done it before.

Leon



"Jassim Rahma"  wrote in message 
news:92616CB7-F48B-4A69-AEFE-C116A175E96A@microsoft.com...
>
> anyone has a code sample to connect the Microsoft Report Viewer Control 
> using Microsoft SQL Server stored procedure?
>
>
>
date: Wed, 23 Jul 2008 01:34:36 +0100   author:   Leon Jollans

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us