2016-10-17 22 views
1

我在ms-sql server 2014中創建了存儲過程並創建了rdlc報告。現在結合中的ReportViewer報告編程,但在報告僅列顯示,而不是數據...reportviewer中未加載數據VB.NET

下面的代碼是我的存儲過程:

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 

我在的ReportViewer形式負載VB.NET代碼事件...

 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中檢查...

另一個VB。 NET代碼我想的是:

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

在這裏,我得到錯誤:

enter image description here

我不知道它說什麼......

幫我在這裏。

回答

2

當前,您已通過DataSet的新實例的DataTable來報告數據源。所以顯然它應該是空的,你會看到沒有任何數據的報告列標題。

您應該將數據加載到DataTable,然後將其傳遞給報告。

例如,如果您在表格上下降了TableAdapter,你可以使用這樣的代碼:

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) 
+0

OMG!我很高興看到我的數據進入ReportViewer Atlast ... #cry ........... Thanx很多。而且,我沒有使用'Dim rds = New Microsoft.Reporting.WinForms.ReportDataSource(「DataSet1」,table)',我直接將表放置在'ReportDataSource1.Value = table'中並且它的工作...謝謝很多@RezaAghaei .. – bonny

+0

實際上我混合兩個代碼,所以有兩個ReportDataSource ...無論如何,我現在感到安心,再次thanx @RezaAghaei – bonny

+0

太棒了!別客氣 :) –