2 mkb21 mkb21 于 2014.10.12 13:11 提问

关于如何向Report1.rdlc传值的问题,请高手指点,万分感谢!

Imports System
Imports System.Data
Imports System.Data.OleDb

Public Class Code

Private Sub Code_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Me.ReportViewer1.RefreshReport()  ' ​初始化报表

    Dim strSQL As String = "Select * From BookView"  '数据库查询语句(使用Access数据库)

    With Me.DataGridView1   '设置DataGridView的一系列属性
        .DataSource = GetDat(strSQL).Tables(0)
        .ReadOnly = True  '只读
        .RowHeadersWidth = 8
        .Columns(0).Width = 96
        .Columns(1).Width = 96
        .AllowUserToResizeColumns = False '禁止调整列宽
        .SelectionMode = DataGridViewSelectionMode.FullRowSelect    '选择模式为整行
    End With
End Sub

Private Shared Function GetDat(ByVal strSql As String) As DataSet

    '数据库连接,建立一个DataSet,返回一个DataSet
    Dim StrConn As String = "Provider= Microsoft.Jet.OLEDB.4.0;Data Source=" &  Application.StartupPath & "\myTry.mdb"

    Dim cn As OleDbConnection = New OleDbConnection(StrConn)
    Dim da As OleDbDataAdapter = New OleDbDataAdapter(strSql, cn)
    Dim ds As DataSet = New DataSet

    Try
        cn.Open()
        da.Fill(ds)
        cn.Close()
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try

    Return ds
End Function

Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
    Dim IntNum As Integer = e.RowIndex
    Dim myNum As String = Me.DataGridView1.SelectedRows(IntNum).Cells(0).ToString
    Dim strSql As String = "Select * From BookCode Where Num = " & myNum
    Dim myTab As Data.DataTable = GetDat(strSql).Tables(0)

    '......下面的代码准备将表中的记录传给报表Report1.rdlc,该如何写?谢谢!

End Sub

End Class
CSDN移动问答

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!