From: Rupinder on 8 Nov 2009 22:25 HI All, I am trying to use a reportviewer control on my Web page to display some reports. I wanted to use the same control to display more than one reports. But when I have a preSelected report every thing works fine. but when I change the report path programmatically I am getting this error. "A data source instance has not been supplied for the data source 'myreport1'" where myreport1 is the Dataset name I have used in my report. Looks like the code is able to read my report but the datasource is not set for the report properly. Please help. thanks, Rupinder Here is the code I am using. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'the objectDataSource1 is the control on my page. ObjectDataSource1.TypeName = "MyDataSource" ObjectDataSource1.SelectMethod = "GetMyData" If Request.QueryString("Report") = "report1" Then ObjectDataSource1.SelectParameters.Add("spname", "rpt_sp1") ObjectDataSource1.SelectParameters.Add("rname", "1") Me.ReportViewer1.ProcessingMode = ProcessingMode.Local Me.ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("MyDS", ObjectDataSource1)) Me.ReportViewer1.LocalReport.ReportPath = "report1.rdlc" Else ObjectDataSource1.SelectParameters.Add("spname", "rpt_sp2") ObjectDataSource1.SelectParameters.Add("rname", "2") Me.ReportViewer1.LocalReport.EnableHyperlinks = True Me.ReportViewer1.ProcessingMode = ProcessingMode.Local Me.ReportViewer1.LocalReport.ReportPath = "report2.rdlc" Me.ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("MyDS", ObjectDataSource1)) End If End Sub The code of the MYDataSource class is as follows Public Class MyDataSource Public Function GetMyData(ByVal spname As String, ByVal rname As String) As DataTable Dim ds As New DataSet() ds.DataSetName = "MyDS" Dim con As String If rname = "1" Then con = ConfigurationManager.ConnectionStrings("Report1ConnectionString").ConnectionString Else con = ConfigurationManager.ConnectionStrings("Report2ConnectionString").ConnectionString End If Dim com As New SqlCommand() com.Connection = New SqlConnection(con) com.Connection.Open() Dim dp As New SqlDataAdapter(spname, con) dp.Fill(ds, "MyTable") Return (ds.Tables(0)) End Function End Class
|
Pages: 1 Prev: TextAlign problem? Next: Subscription Ax data method provider |