Hi

I have a dataset created programatically and I want to use this dataset to bind it to Microsoft ReportViewer.

I tried the Microsoft ReportViewer with DataSet created at design time and it works well.

I have searched a lot and this is the best thing I can find but I see it not logical to create object that simulate the fields in the table. http://aspalliance.com/762

does any one have any thought of how to do it that in case it could be done.

Here is my trial code which is no working

Dim sqlcn As New SqlConnection("server=myserver;uid=myuser;pwd=mypassword;database=mydatabase;")
Dim sadapt As New SqlDataAdapter("select * from mytable", sqlcn)
Dim ds As DataSet = New DataSet
sadapt.Fill(ds, "ds_mytable")
Me.DataGridView1.DataSource = ds.Tables(0)
BindingSource1.DataSource = ds
BindingSource1.DataMember = "ds_mytable"
Dim rptSource1 As New Microsoft.Reporting.WinForms.ReportDataSource
rptSource1.Name = "test"
rptSource1.Value = Me.BindingSource1

Me.ReportViewer1.LocalReport.DataSources.Add(rptSource1)
Me.ReportViewer1.LocalReport.ReportEmbeddedResource = "testing.Report1.rdlc"
Me.ReportViewer1.RefreshReport()

1. Create New Win Project
2. Add a class file into project - Create a sub class of DataSet

Imports System.Data.DataSet
Public Class DBO
    Inherits DataSet
    Private dt As DataTable
    Public Sub New()
        dt = New DataTable("Sample")
        dt.Columns.Add("No", GetType(Integer))
        dt.Columns.Add("Name")
        dt.Rows.Add(1, "A1")
        dt.Rows.Add(2, "A2")
        dt.Rows.Add(3, "A3")
        dt.Rows.Add(4, "A4")
        dt.AcceptChanges()
        Tables.Add(dt)
    End Sub
End Class

3. Build Win application.
4. Add "Report (rdlc) Empty or Wizard.
5. Choose Data source type : Object and so on....
6. Add "MicrosoftReportViewer" Control on Window Form - Choose Report
7. Write following code in Form_Load event

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim db As New DBO
        BindingSource.DataMember = "Sample"
        BindingSource.DataSource = db
        Me.ReportViewer1.RefreshReport()
    End Sub
Comments
Very smart Idea.

Hi adatapost

Thank you very much for this clever idea (create the DataSet as class)

I managed to do it by creating dummy DataSet at design time, but your way is much more better.

It take me long time to put it in my project since i am filling a DataGridView by hand then I have to convert the information in DataGridView to your DataSet and then run the reports.

It works like charm.

Thanks.

Tried this in the past, I couldn't do it and gave up. I'm glad to see that you guys could do that, and I have got to study your solution.
Thanks!

This question has already been answered. Start a new discussion instead.