报表查看器 VB.NET 中未加载数据 [英] Data not Loaded in reportviewer VB.NET

查看:54
本文介绍了报表查看器 VB.NET 中未加载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在 ms-sql server 2014 中创建了存储过程并创建了 rdlc 报告.现在以编程方式在报表查看器中绑定报表,但在报表中只显示列而不显示数据...

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

我在报表查看器表单加载事件中的 VB.NET 代码...

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()

在这里我得到的是列标题而不是数据,数据在那里并在 sql management studio 中检查...

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

我尝试的另一个 VB.NET 代码是:

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()

这里出现错误:

我不知道它在说什么...

I have no Idea what it says...

帮我解决这里.

推荐答案

当前,您已将 DataSet 的新实例的 DataTable 传递给报告数据源.所以很明显它应该是空的,你会看到没有任何数据的报告列标题.

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.

您应该将数据加载到 DataTable 中,然后将其传递给报告.

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

例如,如果您在表单上放置了一个 TableAdapter,您可以使用这样的代码:

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)

还有

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)

这篇关于报表查看器 VB.NET 中未加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆