activeReport3.0 Bind data demo

原创 2007年10月07日 09:29:00
 Imports System
Imports System.Globalization
Imports System.Reflection
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient

#Region "Data Binding Code"
    'btnDataSet_Click -  Illustrates using a DataSet as a data source for an
    'ActiveReport object
    'Author: Data Dynamics, Ltd.
    Private Sub btnDataSet_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDataSet.Click
        Me.Cursor = Cursors.WaitCursor

        'Dataset to hold data
        Dim _InvoiceData As New DataSet()
        _InvoiceData.Locale = CultureInfo.InvariantCulture

        'Database connection populated from the sample Northwind access database
        Dim _nwindConn As New OleDbConnection(GetDBPath.GetNwindConnectString)

        'SQL Select command to run against the database
        Dim _selectCMD As New OleDbCommand("SELECT * FROM Invoices ORDER BY Customers.CompanyName, OrderID", _nwindConn)
        _selectCMD.CommandTimeout = 30

        'Data adapter used to run the select command
        Dim _InvoicesDA As New OleDbDataAdapter()
        _InvoicesDA.SelectCommand = _selectCMD

        'Fill the DataSet
        _InvoicesDA.Fill(_InvoiceData, "Invoices")

        'Create the report and assign the data source
        Dim rpt As New Invoice()
        rpt.DataSource = _InvoiceData
        rpt.DataMember = _InvoiceData.Tables(0).TableName

        'Run and view the report
        rpt.Run(False)
        arvMain.Document = rpt.Document

        Me.Cursor = Cursors.Arrow
    End Sub 'btnDataSet_Click

    'btnDataTable_Click - Illustrates using a DataTable as a data source for an
    'ActiveReport object
    'Author: Data Dynamics, Ltd.
    Private Sub btnDataTable_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDataTable.Click
        Me.Cursor = Cursors.WaitCursor

        'DataTable to hold the data
        Dim _InvoiceData As New DataTable("Invoices")
        _InvoiceData.Locale = CultureInfo.InvariantCulture

        'Database connection populated from the sample Northwind access database
        Dim _nwindConn As New OleDbConnection(GetDBPath.GetNwindConnectString)

        'SQL Select command to run against the database
        Dim _selectCMD As New OleDbCommand("SELECT * FROM Invoices ORDER BY Customers.CompanyName, OrderID", _nwindConn)
        _selectCMD.CommandTimeout = 30

        'Data adapter used to run the select command
        Dim _InvoicesDA As New OleDbDataAdapter()
        _InvoicesDA.SelectCommand = _selectCMD

        'Fill the DataTable
        _InvoicesDA.Fill(_InvoiceData)

        'Create the report and assign the data source
        Dim rpt As New Invoice()
        rpt.DataSource = _InvoiceData

        'Run and view the report
        rpt.Run(False)
        arvMain.Document = rpt.Document

        Me.Cursor = Cursors.Arrow
    End Sub 'btnDataTable_Click

    'btnDataView_Click - Illustrates using a DataView as a data source for an
    'ActiveReport object
    'Author: Data Dynamics, Ltd.
    Private Sub btnDataView_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDataView.Click
        Me.Cursor = Cursors.WaitCursor

        'Verify that a value Company Name is selected
        If Me.cbCompanyName.SelectedItem Is Nothing Then
            MessageBox.Show("Please select a Company Name first.")
            Me.Cursor = Cursors.Arrow

            Return
        End If

        'DataTable to hold the full data
        Dim _InvoiceData As New DataTable("Invoices")
        _InvoiceData.Locale = CultureInfo.InvariantCulture

        'Database connection populated from the sample Northwind access database
        Dim _nwindConn As New OleDbConnection(GetDBPath.GetNwindConnectString)

        'SQL Select command to run against the database
        Dim _selectCMD As New OleDbCommand("SELECT * FROM Invoices ORDER BY Customers.CompanyName, OrderID", _nwindConn)
        _selectCMD.CommandTimeout = 30

        'Data adapter used to run the select command
        Dim _InvoicesDA As New OleDbDataAdapter()
        _InvoicesDA.SelectCommand = _selectCMD

        'Fill the DataTable
        _InvoicesDA.Fill(_InvoiceData)

        'Create DataView and assign the selected CompanyName RowFilter
        Dim _InvoiceDataView As New DataView(_InvoiceData)
        _InvoiceDataView.RowFilter = "Customers.CompanyName='" + Convert.ToString(Me.cbCompanyName.SelectedItem).Replace("'", "''") + "'"

        'Create the report and assign the data source
        Dim rpt As New Invoice()
        rpt.DataSource = _InvoiceDataView

        'Run and view the report
        rpt.Run(False)
        arvMain.Document = rpt.Document

        Me.Cursor = Cursors.Arrow
    End Sub 'btnDataView_Click

    'btnDataReader_Click - Illustrates using a DataReader as a data source for an
    'ActiveReport object
    'Author: Data Dynamics, Ltd.
    Private Sub btnDataReader_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDataReader.Click
        Me.Cursor = Cursors.WaitCursor

        'Database connection populated from the sample Northwind access database
        Dim _nwindConn As New OleDbConnection(GetDBPath.GetNwindConnectString)

        'SQL Select command to run against the database
        Dim _selectCMD As New OleDbCommand("SELECT * FROM Invoices ORDER BY Customers.CompanyName, OrderID", _nwindConn)
        _selectCMD.CommandTimeout = 30

        'DataReader to use to read the data
        Dim _InvoiceDataReader As OleDbDataReader

        'Open the database connection and Execute the reader
        _nwindConn.Open()
        _InvoiceDataReader = _selectCMD.ExecuteReader()

        'Create the report and assign the data source
        Dim rpt As New Invoice()
        rpt.DataSource = _InvoiceDataReader

        'Run and view the report
        rpt.Run(False)
        arvMain.Document = rpt.Document

        'Close the database connection
        _nwindConn.Close()

        Me.Cursor = Cursors.Arrow
    End Sub 'btnDataReader_Click

    'btnOleDb_Click - Illustrates using a Data Dynamics OleDb object as a data source
    'for an ActiveReport object
    'Author: Data Dynamics, Ltd.
    Private Sub btnOleDb_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOleDb.Click
        Me.Cursor = Cursors.WaitCursor

        'OleDb Data Source object to use
        Dim _OleDb As New DataDynamics.ActiveReports.DataSources.OleDBDataSource()

        'Assign the database connection string from the sample Northwind access database
        _OleDb.ConnectionString = GetDBPath.GetNwindConnectString
        'SQL Select command to run against the database
        _OleDb.SQL = "SELECT * FROM Invoices ORDER BY Customers.CompanyName, OrderID"

        'Create the report and assign the data source
        Dim rpt As New Invoice()
        rpt.DataSource = _OleDb

        'Run and view the report
        rpt.Run(False)
        arvMain.Document = rpt.Document

        Me.Cursor = Cursors.Arrow
    End Sub 'btnOleDb_Click

    'btnSqlServer_Click - Illustrates using a Data Dynamics SqlServer object as a data source
    'for an ActiveReport object
    'Author: Data Dynamics, Ltd.
    Private Sub btnSqlServer_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSqlServer.Click
        Me.Cursor = Cursors.WaitCursor

        'Verify that a SQL Server has been selected
        If Me.cbSqlServerList.SelectedItem Is Nothing Then
            MessageBox.Show("Please select a SQL Server first.")
            Me.Cursor = Cursors.Arrow
            Return
        End If

        'SqlServer Data Source object to use
        Dim _SQL As New DataDynamics.ActiveReports.DataSources.SqlDBDataSource()

        'Assign the database connection string based on the SQL Server selected
        _SQL.ConnectionString = "Data Source=" + Me.cbSqlServerList.SelectedItem + ";Initial Catalog=Northwind;Integrated Security=SSPI"
        'SQL Select command to run against the database
        _SQL.SQL = "SELECT * FROM invoices ORDER BY CustomerID, OrderID"

        'Create the report and assign the data source
        Dim rpt As New Invoice()
        rpt.DataSource = _SQL

        'Run and view the report
        Try
            rpt.Run(False)
            arvMain.Document = rpt.Document
        Catch ex As System.Data.SqlClient.SqlException
            MessageBox.Show(ex.Message)
        End Try

        Me.Cursor = Cursors.Arrow
    End Sub 'btnSqlServer_Click

    'btnGenerateXML_Click - Generates a DataSet and saves it out as an XML data file
    'to the user selected file name
    'Author - Data Dynamics, Ltd.
    Private Sub btnGenerateXML_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGenerateXML.Click
        'DataSet used to hold the Data
        Dim _InvoiceData As New DataSet("Northwind")
        _InvoiceData.Locale = CultureInfo.InvariantCulture

        'Database connection populated from the sample Northwind access database
        Dim _nwindConn As New OleDbConnection(GetDBPath.GetNwindConnectString)

        'SQL Select command to run against the database
        Dim _selectCMD As New OleDbCommand("SELECT * FROM Invoices ORDER BY Customers.CompanyName, OrderID", _nwindConn)
        _selectCMD.CommandTimeout = 30

        'Data adapter used to run the select command
        Dim _InvoicesDA As New OleDbDataAdapter()
        _InvoicesDA.SelectCommand = _selectCMD

        'Fill the DataSet
        _InvoicesDA.FillSchema(_InvoiceData, SchemaType.Source, "Invoices")
        _InvoiceData.Tables("Invoices").Columns("OrderDate").DataType = System.Type.GetType("System.String")
        _InvoiceData.Tables("Invoices").Columns("ShippedDate").DataType = System.Type.GetType("System.String")
        _InvoicesDA.Fill(_InvoiceData, "Invoices")

        'Initalize the Save Dialog Box
        dlgSave.Title = "Save Data As..."
        dlgSave.FileName = "Invoices.xml"
        dlgSave.Filter = "XML Data (*.xml)|*.xml"
        dlgSave.ShowDialog()

        Dim x As Integer
        'If valid name is returned, save out the DataSet to the specified filename
        If dlgSave.FileName.Length <> 0 Then
            'Format all date fields in the XML for the report
            For x = 0 To _InvoiceData.Tables("Invoices").Rows.Count - 1
                _InvoiceData.Tables("Invoices").Rows(x)("OrderDate") = Convert.ToDateTime(_InvoiceData.Tables("Invoices").Rows(x)("OrderDate")).ToShortDateString()
                If Not _InvoiceData.Tables("Invoices").Rows(x)("ShippedDate").GetType() Is Type.GetType("System.DBNull") Then
                    _InvoiceData.Tables("Invoices").Rows(x)("ShippedDate") = Convert.ToDateTime(_InvoiceData.Tables("Invoices").Rows(x)("ShippedDate")).ToShortDateString()

                End If
            Next

            _InvoiceData.WriteXml(dlgSave.FileName)
        End If
    End Sub 'btnGenerateXML_Click

    'btnXML_Click - Illustrates using a Data Dynamics XML object as a data source
    'for an ActiveReport object
    'Author: Data Dynamics, Ltd.
    Private Sub btnXML_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnXML.Click
        'Initialize the Open Dialog Box
        dlgOpen.Title = "Open Data File..."
        dlgOpen.FileName = dlgSave.FileName
        dlgOpen.Filter = "XML Data (*.xml)|*.xml"
        dlgOpen.ShowDialog()

        'If valid name is returned, open the data and run the report
        If dlgOpen.FileName.Length <> 0 Then
            Me.Cursor = Cursors.WaitCursor

            'XML Data Source object to use
            Dim _XML As New DataDynamics.ActiveReports.DataSources.XMLDataSource()

            'Assign the FileName for the selected XML data file
            _XML.FileURL = dlgOpen.FileName
            'Assign the Recordset Pattern
            _XML.RecordsetPattern = "//Northwind/Invoices"

            'Create the report and assign the data source
            Dim rpt As New Invoice()
            rpt.DataSource = _XML

            'Run and view the rpeort
            rpt.Run(False)
            arvMain.Document = rpt.Document

            Me.Cursor = Cursors.Arrow
        End If
    End Sub 'btnXML_Click
#End Region

Imports System

' GetDBPath is a helper class used to locate the Northwind sample database on the computer.
    ' Author: Data Dynamics, Ltd.
   NotInheritable Class GetDBPath
    
      Private Sub New()
      End Sub 'New

    Private Shared registryKey As String = "SOFTWARE/Data Dynamics/ActiveReports for .NET 3.0/SampleDB"

    ' Used to get the path to the Sample database installed with ActiveReports
    ' Author: Data Dynamics, Ltd.
    ' Returns: String variable with the path to the Sample Database
    Public Shared Function GetPath() As String
        Dim sPath As String = Nothing
        Try
            ' Create a RegistryKey value to retrieve the localmachine entries, and open the subkey that points to the database
            Dim hklm As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine
            Dim sampleDbKey As Microsoft.Win32.RegistryKey = hklm.OpenSubKey(registryKey)
            sPath = sampleDbKey.GetValue("") '

        Catch eReg As System.Exception
            ' problem occured with attempting to read the local registry (No access rights for current user?)
            Throw New System.ApplicationException("An error occured accessing the registry key " & registryKey & ".", eReg)
        End Try
        If sPath Is Nothing Then
            ' we couldn't read the registry
            Throw New System.ApplicationException("Unable to access the sample database registry value " & registryKey & ".")
        End If
        Return sPath
    End Function 'GetPath

    ' Used to get the full connection string to the Sample Database installed with ActiveReports
    ' Author: Data Dynamics, Ltd.
    ' Returns: String variable with the full connection string to the Sample Database     
    Public Shared ReadOnly Property GetNwindConnectString() As String
        Get
            Return "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" + GetDBPath.GetPath() + "/nwind.mdb"
        End Get
    End Property
End Class 'GetDBPath

SpringMVC学习系列(5) 之 数据绑定-2

SpringMVC学习系列(5) 之 数据绑定-2 在系列(4)中我们介绍了如何用@RequestParam来绑定数据,下面我们来看一下其它几个数据绑定注解的使用方法。 1.@Pa...
  • huhui0406
  • huhui0406
  • 2016年12月07日 21:30
  • 236

【IOS学习】Core Data 框架学习笔记,以及demo

关于Core data 设计用来与MVC设计模式协同工作的 关注的是对象,从Core Data 获取信息时,会创建并返回一个装有受控对象(managed object)的数组 返回的数据结构由模...
  • mangosnow
  • mangosnow
  • 2014年07月05日 17:41
  • 3651

Jquery on()方法 替代live(),bind()绑定事件

jquery1.7版本出现之后用于替代bind(),live()绑定事件方式; 简要描述  on() 为指定的元素,添加一个或多个事件处理程序,并规定当这些事件发生时运行的函数。使用 on() 方法...
  • shenyingzgd
  • shenyingzgd
  • 2015年09月30日 16:51
  • 1411

Chromium的智能指针/引用计数/Callback/Bind

本文算是个笔记整理,不解释基本概念,有做相关工作的人才看懂哦。一、自动释放指针智能指针分两类,对有和没有引用计数实现的类做区分。没有引用计数的类,使用scoped_ptr。这个模板类中的D是指Dele...
  • hursing
  • hursing
  • 2014年08月23日 14:24
  • 4808

百度分享——1

  • u012260672
  • u012260672
  • 2016年04月13日 21:21
  • 312

Spark+Alluxio的使用初级(转自官网)

Getting Started with Alluxio and Spark 04.14.2016 | Calvin Jia 86Click to share on...
  • zy_zhengyang
  • zy_zhengyang
  • 2016年09月13日 16:18
  • 445

Bind 搭建 DNS(应用:域名方式配置分布式集群,扩展方便)

bind搭建dns
  • wangxilong1991
  • wangxilong1991
  • 2017年04月20日 14:57
  • 396

(D3学习)绑定数据(binding data)

D3.js中的绑定数据(binding data)
  • syoya1997
  • syoya1997
  • 2016年12月07日 14:08
  • 827

Socket层实现系列 — bind()的实现(一)

bind()函数的使用方法很简单,但是它是怎么实现的呢? 笔者从应用层出发,沿着网络协议栈,分析了bind()的系统调用、Socket层实现,以及它的TCP层实现。 本文主要内容:bind()的系统...
  • zhangskd
  • zhangskd
  • 2013年11月11日 16:50
  • 15883

linux网络编程/tcp_server中server bind失败原因的调研

问题模型:server1为服务端,在本地的9999端口监听,server2相对server1是客户端,server2启动后首先向server1发起连接,然后再8888端口监听。程序代码不在列出。先后启...
  • s25691011
  • s25691011
  • 2017年06月26日 11:34
  • 975
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:activeReport3.0 Bind data demo
举报原因:
原因补充:

(最多只允许输入30个字)