ReportViewer problem !

  • 14 years ago

    Hi all. Sorry about my poor English.

    I'm new in VS2005. When i work with Report Viewer, I got a problem:
    1. I make a report rdl name : report1.rdl (xml schema only take from dataset)
    2. Create Win Application and ReportViewer
    3. I'm code :

    Public Class Form2

        Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim objDS As ObjectDataSource = New ObjectDataSource("MyDataSource2", "GetData")
            objDS.ID = "DataSet1"

            ReportViewer1.LocalReport.DataSources.Clear()
            ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("DataSet1", objDS.ID))
            ReportViewer1.LocalReport.ReportPath = "report1.rdl"


            'prepare report data source
            Dim rds As ReportDataSource = New ReportDataSource
            rds.Value = MyDataSource2.GetData()
            ReportViewer1.LocalReport.DataSources.Add(rds)

            Me.ReportViewer1.RefreshReport()
        End Sub

        Public Class MyDataSource2

            Public Shared Function GetData() As DataTable
                Dim ds As New DataSet
                Dim con As New SqlConnection("Data Source=(local);Initial Catalog=AdventureWorks;Persist Security Info=True;User ID=sa;Password=1")
                Dim strSelect As String = "SELECT Person.CountryRegion.Name AS CountryName, Person.StateProvince.Name AS StateProvince FROM Person.StateProvince INNER JOIN Person.CountryRegion ON Person.StateProvince.CountryRegionCode = Person.CountryRegion.CountryRegionCode ORDER BY Person.CountryRegion.Name"

                Dim dp As New SqlDataAdapter(strSelect, con)
                dp.Fill(ds, "DataSet1")
                Return ds.Tables(0)
            End Function
        End Class

    End Class

    But, it can't display data when run reportviewer. It show column name only as below :    








































    CountryName         StateProvince

    and it don't show any data. But when I preview RDL report in VS2005, it show full data.

    Please help me.

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“If Java had true garbage collection, most programs would delete themselves upon execution.” - Robert Sewell