GridReport 5.0 报表的使用

来源:互联网 发布:sql默认实例 编辑:程序博客网 时间:2024/06/07 18:28

 

 连接:

   'GripReport 连接语句  GRID Report 连接到的数据库
    Public ConnectStringForGridReport As String = "Provider=SQLOLEDB.1;Password=password;Persist Security Info=True;User ID=sa;Initial Catalog=DBName;Data Source=SQL Server;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=**PC003;Use Encryption for Data=False;Tag with column collation when possible=False"

 

引用:

      Interop.grproLib,AxInterop.grproLib

定义:

        Imports grproLib

        Private Report0 As New GridppReport

使用:

        Report0.LoadFromFile("" & Application.StartupPath & "\gridreport.grf")
        Report0.DetailGrid.Recordset.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=\\10.10.10.10\IQCDatabase\Access2003.mdb;Password=;Jet OLEDB:Database Password='password'"
        Report0.DetailGrid.Recordset.QuerySQL = "Select * From "'"

        '设置报表查询显示器控件的关联报表对象
        AxGRDisplayViewer1.Report = Report0
        '启动报表运行

         Report.DetailGrid.FixCols = 2         '锁定为两行
        AxGRDisplayViewer1.Start()

 

第二种:多条记录的情况    

                Frm员工信息报表.AxGRDisplayViewer1.Stop()
                AddHandler Report.FetchRecord, AddressOf SimpleEmployeeQuery   '指针 + 地址  这一句可以不加

 

        Report.LoadFromFile(Application.StartupPath & "\reports\GridReport.grf")
        Report.PrepareRecordset()                '这句一定要加 否则出错

 

    Private Structure MatchFieldPairType
        Public grField As IGRField
        Public MatchColumnIndex As Integer
    End Structure      '结构体

 

  Public Shared Sub FillRecordToReport(ByVal Report As IGridppReport, ByVal dt As DataTable)
        Dim MatchFieldPairs() As MatchFieldPairType
        ReDim MatchFieldPairs(Math.Min(Report.DetailGrid.Recordset.Fields.Count, dt.Columns.Count))

        '根据字段名称与列名称进行匹配,建立DataReader字段与Grid++Report记录集的字段之间的对应关系
        Dim MatchFieldCount As Integer
        MatchFieldCount = 0
        Dim I As Integer
        For I = 0 To dt.Columns.Count - 1
            Dim fld As IGRField
            For Each fld In Report.DetailGrid.Recordset.Fields
                If String.Compare(fld.Name, dt.Columns.Item(I).ColumnName, True) = 0 Then
                    MatchFieldPairs(MatchFieldCount).grField = fld
                    MatchFieldPairs(MatchFieldCount).MatchColumnIndex = I
                    MatchFieldCount = MatchFieldCount + 1
                    Exit For
                End If
            Next fld
        Next

        '将 DataTable 中的每一条记录转储到Grid++Report 的数据集中去
        Dim dr As DataRow
        For Each dr In dt.Rows

            Report.DetailGrid.Recordset.Append()

            For I = 0 To MatchFieldCount - 1
                If Not dr.IsNull(MatchFieldPairs(I).MatchColumnIndex) Then
                    MatchFieldPairs(I).grField.Value = dr.Item(MatchFieldPairs(I).MatchColumnIndex)
                End If
            Next

            Report.DetailGrid.Recordset.Post()
        Next
    End Sub   'DataTable的GridReport的填充方式

    Public Shared Sub FillRecordToReport(ByVal Report As IGridppReport, ByVal dr As SqlDataReader)

        Dim MatchFieldPairs() As MatchFieldPairType
        ReDim MatchFieldPairs(Math.Min(Report.DetailGrid.Recordset.Fields.Count, dr.FieldCount))

        '根据字段名称与列名称进行匹配,建立DataReader字段与Grid++Report记录集的字段之间的对应关系
        Dim MatchFieldCount As Integer
        MatchFieldCount = 0
        Dim i As Integer
        For i = 0 To dr.FieldCount - 1
            Dim fld As IGRField
            For Each fld In Report.DetailGrid.Recordset.Fields
                If String.Compare(fld.RunningDBField, dr.GetName(i), True) = 0 Then
                    MatchFieldPairs(MatchFieldCount).grField = fld
                    MatchFieldPairs(MatchFieldCount).MatchColumnIndex = i
                    MatchFieldCount = MatchFieldCount + 1
                    Exit For
                End If
            Next fld
        Next

        'Loop through the contents of the OleDbDataReader object.
        '将 DataReader 中的每一条记录转储到Grid++Report 的数据集中去

        Report.DetailGrid.Recordset.Append()

        For i = 0 To MatchFieldCount - 1

            If Not dr.IsDBNull(MatchFieldPairs(i).MatchColumnIndex) Then
                MatchFieldPairs(i).grField.Value = dr.GetValue(MatchFieldPairs(i).MatchColumnIndex)
            End If
        Next

        Report.DetailGrid.Recordset.Post()

    End Sub           'DataReader的GridReport的填充方式

 

 

客户端: 注册

      regsvr32 grdes50.dll
     regsvr32 gregn50.dll

 

原创粉丝点击