开发者

Binding a datasource to a rdl in report server programmatically - SSRS

开发者 https://www.devze.com 2022-12-21 20:22 出处:网络
I\'ve done a asp.net application to generate reports over a particular data. Initially i created local reports (.rdlc) to generate reports. I created separate .xsd for each rdlc and designed the repor

I've done a asp.net application to generate reports over a particular data. Initially i created local reports (.rdlc) to generate reports. I created separate .xsd for each rdlc and designed the reports. I build the dataset programmatically and bind it to the rdlc. I used the following code for binding the datasource to the reports -

rptMyReport.LocalReport.ReportPath = Server.MapPath(srdlcName);
rptMyReport.LocalReport.DataSources.Add(rds);

Now i have converted all the rdlc to rdl following this msdn article and i've published the reports to the report server.

rptMyReport.ServerReport.ReportServerUrl = new System.Uri("http://ReportServer/ReportServer");
rptMyReport.Server开发者_StackOverflowReport.ReportPath = "/ReportFolder/ReportName";

Now how can i set the datasource to the reports programmatically?


This work is impossible. you should create your datasource in your rdl report. you must write needed queries for report data gathering. you can use this query as a text or stored procedure. You can pass parameters to this query and filter the output of the query. you can only pass the parameters to rdl report like this:

ReportParameter[] Params = new ReportParameter[1];
Params[0] = "Parameter Value";
ReportViewerControl.ServerReport.SetParameters(Params);


What are you trying to do? I believe the datasource is mentioned within the .RDL file itself. For ex: When you create an Report using BIDS, you can specify the datasource. This gets added to the .RDL file. The same concept holds true here as well.


This is not impossible, but may take a little effort if this is what you want to do.
You have a couple of options:

  1. If you create a shared datasource on your report server you can add it manually using the RDLObjectModel. Get the shared datasource name and guid from your reportserver and you can add it to your report.

    Example:

    'create the datasource for the report
    Dim dataSrcRFoo = New RdlObjectModel.DataSource
    dataSrcRFoo.Name = "DataSourceName"
    dataSrcRFoo.DataSourceReference = "/path/to/DataSource"
    dataSrcRFoo.IsShared = True
    dataSrcRFoo.SecurityType = 2 ' RdlObjectModel.SecurityTypeEnum.DataBase   
    dataSrcRFoo.DataSourceID = New Guid("shareddatasourceguid")
    
    'add data source to report
    rdlRpt.DataSources.Add(dataSrcRFoo) 
    
  2. Another option is to use templates on the server that have the share (or report level) datasource built in.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号