Data not Loaded in reportviewer VB.NET

2019-04-15 14:03发布

I have created the stored procedure in ms-sql server 2014 and creating the rdlc report. Now binding the report in reportviewer programatically, but in report only columns are displayed and not the data...

The below code is my stored procedure :

USE [Bonny]
GO
/****** Object:  StoredProcedure [dbo].[AccMast_AllDetail]    Script Date: 17/10/2016 12:10:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Proc [dbo].[AccMast_AllDetail]
as
Select Account_Code,Party_Name,Address_1,Address_2,City from FAMPAR order by Account_Code
GO

My VB.NET code in reportviewer form load event...

        ReportViewer.Reset()
        Dim data As New AccMastDataSet
        Dim ReportDataSource1 As ReportDataSource = New ReportDataSource
        ReportDataSource1.Name = "AccMastDataSet"
        ReportDataSource1.Value = rds
        ReportViewer.LocalReport.DataSources.Clear()
        ReportViewer.LocalReport.DataSources.Add(ReportDataSource1)
        ReportViewer.LocalReport.ReportEmbeddedResource = "Report1.rdlc"
        ReportViewer.LocalReport.ReportPath = "D:\netbonny\netbonnyproject\netbonnyproject\Reports\Report1.rdlc"
        ReportViewer.RefreshReport()

In this I am getting column headers but not the Data, data is there and checked in sql management studio...

Another VB.NET code I tried is :

Dim data As New AccMastDataSet
Dim abc = data.Tables("AccMast_AllDetail")
Dim rds = New Microsoft.Reporting.WinForms.ReportDataSource("AccMastDataSet", data)
ReportViewer.LocalReport.DataSources.Clear()
ReportViewer.LocalReport.DataSources.Add(rds)
ReportViewer.LocalReport.ReportEmbeddedResource = "netbonnyproject.Report1.rdlc"
ReportViewer.RefreshReport()

Here I am getting error :

enter image description here

I have no Idea what it says...

Help me out in here.

1条回答
走好不送
2楼-- · 2019-04-15 14:54

Currently you have passed a DataTable of a new instance of a DataSet to report data source. So obviously it should be empty and you will see report column headers without any data.

You should load data into the DataTable and then pass it to report.

For example, if you dropped a TableAdapter on your form, you can use such code:

Me.Table1TableAdapter.Fill(Me.DataSet1.Table1)
Dim rds = New Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", Me.DataSet1.Table1)

Also

Dim cn = "Connection String"
Dim cmd = "Stored Procedre Name"
Dim table = New DataTable()
Using adapter As New SqlDataAdapter(cmd, cn)
    adapter.SelectCommand.CommandType = CommandType.StoredProcedure
    adapter.Fill(table)
End Using
Dim rds = New Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", table)
查看更多
登录 后发表回答