Bind reportviewer to Dataset or Dattable in runtime
Hi everybody,
I would like to bind my reportviewer to my dataset or datatable in run time (I do not want to use any wizard) in C# 2008.
is there anyway to do it? I searched for for hours, but I did not find any solution for my idea.
Thank you in advance for your time.
December 16th, 2010 4:53pm
Here is a sample snippet you can try:
Private
Sub FillData()
' Get Data from DataSource to a DataSet
Dim strCon As
New SqlConnection("Use the ConnectionString to connect to the db Server")
Dim strDa
As New
SqlDataAdapter("Specify the Select Statement", strCon)
Dim ds As
New DataSet()
strDa.Fill(ds)
' Define a ReportDataSource Object
Dim ReportDataSource2 As Microsoft.Reporting.WinForms.ReportDataSource =
New Microsoft.Reporting.WinForms.ReportDataSource()
Me.ReportViewer1.LocalReport.DataSources.Clear()
' Assign the previously created DataSet as the Report DataSource
ReportDataSource2.Value = ds.Tables(0)
' Make sure the name of the DataSet is same as that of the DataSet being defined for the Local Report
ReportDataSource2.Name =
"DataSet1"
ReportViewer1.LocalReport.DataSources.Add(ReportDataSource2)
Me.ReportViewer1.RefreshReport()
End Sub
Hope this helps!!Chaitanya
Free Windows Admin Tool Kit Click here and download it now
December 17th, 2010 2:06am
Hi Alex_00,
You could also refer to these links:
Using the WebForms ReportViewer Control
http://msdn.microsoft.com/en-us/library/aa337091(SQL.90).aspx
Samples and Walkthroughs
http://msdn.microsoft.com/en-us/library/ms251686(v=VS.90).aspx
Thanks,
Challen Fu [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
December 17th, 2010 6:37am
Hi Challen,
The web site is very useful as well, I learned a lot form it
Again thank you for your time
Alex
Free Windows Admin Tool Kit Click here and download it now
December 17th, 2010 10:14am
Hi Challen,
The web site is very useful as well, I learned a lot for it
Again thank you for your time
Alex
December 17th, 2010 10:14am