我已设法将reportview添加到我的visual studio 2015项目中,但我的代码无效
这是代码:
Imports System.Data.OleDb
Imports Microsoft.Reporting.WinForms
Public Class FRMREPORTS
Dim CN As OleDbConnection = Nothing
Dim CM As OleDbCommand = Nothing
Dim CN_S As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\FILECAB.accdb"
Dim SQL_S As String = ""
Dim UP_STR As String = ""
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
GET_DATA()
LOAD_REPORT()
RVIEW.RefreshReport()
End Sub
Public Sub GET_DATA()
Try
Dim SQL_R As String = "SELECT * From ITEMS"
Dim CN As New OleDbConnection(CN_S)
Dim D_A As New OleDbDataAdapter(SQL_R, CN)
Dim DS As New DataSet()
CN.Open()
D_A.Fill(DS, "ITEM_TABLE")
CN.Close()
DG_ITMES.DataSource = DS.Tables("ITEM_TABLE")
'Dim RDS As ReportDataSource = New ReportDataSource("ITEM_TABLE", DS.Tables)
'RVIEW.LocalReport.DataSources.Add(RDS)
With DG_ITMES
.Columns(0).HeaderCell.Value = "ID"
.Columns(1).HeaderCell.Value = "Category"
.Columns(2).HeaderCell.Value = "Description"
.Columns(3).HeaderCell.Value = "Unit"
.Columns(0).Visible = False
.Columns(1).Width = 150
.Columns(2).Width = 300
.Columns(3).Width = 150
.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
End With
SQL_R = Nothing
If CN.State = ConnectionState.Open Then CN.Close()
D_A = Nothing
DS = Nothing
Catch ex As Exception
MsgBox(Err.Description)
End Try
End Sub
Public Sub LOAD_REPORT()
Try
RVIEW.LocalReport.DataSources.Clear()
Dim DT As New DataTable
With DT
.Columns.Add("ID")
.Columns.Add("Category")
.Columns.Add("Description")
.Columns.Add("Unit")
End With
For Each row As DataGridViewRow In DG_ITMES.Rows
DT.Rows.Add(row.Cells(0).Value, row.Cells(1).Value, row.Cells(2).Value, row.Cells(3).Value)
Next
Dim RDS As ReportDataSource = New ReportDataSource(DT.TableName, DT)
RVIEW.LocalReport.DataSources.Add(RDS)
Catch ex As Exception
MsgBox(Err.Description)
End Try
End Sub
End Class
当我运行这个时,我从报告视图中获得“尚未指定报告定义的来源”