Binding Data to the ReportViewer Control Dynamically in ASP.NET 2.0 - Binding a SELECT statement to a ReportViewer control in ASP.NET 2.0: code
(Page 2 of 6 )
Once you have created the datasets and reports as given in the previous section, we need to work with the ReportViewer control to render the data based on the dynamic SELECT.
Drag a ReportViewer control onto the default.aspx and modify your code-behind file in such a way that it looks something like the following:
ImportsMicrosoft.Reporting.WebForms
ImportsSystem.Data
ImportsSystem.Data.Sqlclient
PartialClass _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Set the processing mode for the ReportViewer to Local
ReportViewer1.ProcessingMode = ProcessingMode.Local
Dim rep As LocalReport = ReportViewer1.LocalReport
rep.ReportPath = "SampleReport.rdlc"
Dim ds As DataSet = GetSalesData()
'Create a report data source for the sales order data
Dim dsSalesOrder As New ReportDataSource()
dsSalesOrder.Name = "SalesData_Data"
dsSalesOrder.Value = ds.Tables("SalesData")
rep.DataSources.Add(dsSalesOrder)
End Sub
Private Function GetSalesData()
Dim ds As New DataSet
Dim sqlSalesData As String = _
"SELECT SalesPersonID, FirstName, " & _
" SalesQuota, SalesYTD, SalesLastYear " & _
"FROM Sales.vSalesPerson "
Using connection As New SqlConnection( _
"Data Source=(local)sql2k5; " & _
"Initial Catalog=AdventureWorks; " & _
"Integrated Security=SSPI")
Dim command As New SqlCommand(sqlSalesData,
connection)
Dim salesOrderAdapter As New SqlDataAdapter(command)
salesOrderAdapter.Fill(ds, "SalesData")
salesOrderAdapter.Dispose()
command.Dispose()
End Using
Return ds
End Function
EndClass
Next: Binding an XML document to a ReportViewer control in ASP.NET 2.0 >>
More ASP.NET Articles
More By Jagadish Chaterjee