Statsar Statistics Library

v1.0.1 for .NET

Product Guide



More Information...

Valid XHTML


Access Database Example (VB.NET)

[VB.NET]
' COPYRIGHT(C), SIMPLEXAR SOFTWARE LIMITED, 2006-2008.
' All rights reserved.
'
' Use of this copyright notice is precautionary only, and does not imply
' publication or disclosure. The content of this work contains confidential
' and proprietary information of Simplexar Software Limited. Any duplication,
' modification, distribution, or disclosure in any form, in whole, or in part,
' is strictly prohibited without express prior written permission.

' Get namespaces.
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports Simplexar.Statsar

' Start namespace.
Namespace Simplexar.Examples.Statsar

    ' This example demonstrates how to import data from an ADO.NET data table
    ' by connecting to a Microsoft Access database and loading data.
    Module Example

        ' The application entry point.
        Public Sub Main()
            Try
                RunExample()
            Catch exception As Exception
                Console.WriteLine(exception)
            End Try
            Console.WriteLine("Press ENTER to terminate.")
            Console.ReadLine()
        End Sub

        Private Sub RunExample()

            ' Create a calculator.
            Dim calculator As New StatsCalculator()

            ' Get data table from database.
            Dim dataTable As DataTable = GetDataTable()

            ' Set data table as calculator data source.
            calculator.DataSource = dataTable
            Dim sheet As DataSheet = calculator.Sheet
            Console.WriteLine(sheet)

        End Sub

        Private Function GetDataTable() As DataTable

            ' Specify connection string.
            Dim connectionString As String = String.Format("{0}{1}", _
                "Provider=Microsoft.Jet.OLEDB.4.0;", _
                "Data Source=..\..\..\..\..\Data\AccessDatabase.mdb;")

            ' Connect and initiate SELECT command.
            Dim connection As New OleDbConnection(connectionString)
            Dim command As New OleDbCommand( _
                "SELECT * FROM GDP", connection)

            ' Fill data table.
            Dim adapter As New OleDbDataAdapter(command)
            Dim dataTable As New DataTable()
            adapter.Fill(dataTable)

            ' Dispose managed resources.
            adapter.Dispose()
            command.Dispose()
            connection.Dispose()

            Return dataTable

        End Function

    End Module

End Namespace