Home

ADO.NET and Paradox

 

Introduction

ADO.NET allows you to create a GUI database application that can connect to almost any type of database used on Microsoft Windows. Besides SQL Server, Microsoft Access, and Oracle, you can also create an application that connects to a Paradox database. This can be done through ODBC as implemented in ADO.NET.

Database Creation

If you plan to create a database application that would use a Paradox database, you can start by opening Paradox. After launching Paradox, locate the directory alias you want to use or create one. For this application, we will use the C:\Programs\FunctionX directory and we had created its alias as Data

After creating or locating the alias and selecting it in Paradox, you can create the necessary table(s) by clicking File -> New -> Table... from Paradox' main menu:

After creating the table, you should save it:

After creating and saving the table, you can enter a few records to test it. To do this, you can first close then open it and click View -> Edit Data from the main menu:

Creating a Data Source

To create a connection to a Paradox database, you can use ODBC as it is featured in ADO.NET. Before doing this, you can create a data source. To do this, you can double-click the Data Source (ODBC) icon from Control Panel. In the ODBC Data Source Administrator, click New. In the the Create New Data Source dialog box, select Microsoft Paradox Driver (*.db):

Click Finish. In the ODBC Paradox Setup dialog box, enter a name in the Data Source Name text box:

Click OK twice.

 

Application Creation

After creating a Paradox table and its ODBC data source, you can start a Windows Forms Application like any other. In its simplest format, you can equip a for with a DataGrid control and a button as follows:

To create a connection to a Paradox table, you can first declare a variable of type OdbcConnection. You can either use its second constructor that takes a string or you can access its ConnectionString property. Either of these allows you to specify how the connection would be carried. Here is an example:

Imports System.Data
Imports System.Data.Odbc

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents btnClose As System.Windows.Forms.Button
    Friend WithEvents btnLoad As System.Windows.Forms.Button
    Friend WithEvents dataGrid1 As System.Windows.Forms.DataGrid
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.btnClose = New System.Windows.Forms.Button
        Me.btnLoad = New System.Windows.Forms.Button
        Me.dataGrid1 = New System.Windows.Forms.DataGrid
        CType(Me.dataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'btnClose
        '
        Me.btnClose.Location = New System.Drawing.Point(272, 168)
        Me.btnClose.Name = "btnClose"
        Me.btnClose.TabIndex = 5
        Me.btnClose.Text = "Close"
        '
        'btnLoad
        '
        Me.btnLoad.Location = New System.Drawing.Point(16, 168)
        Me.btnLoad.Name = "btnLoad"
        Me.btnLoad.TabIndex = 4
        Me.btnLoad.Text = "Load"
        '
        'dataGrid1
        '
        Me.dataGrid1.AlternatingBackColor = System.Drawing.Color.WhiteSmoke
        Me.dataGrid1.BackColor = System.Drawing.Color.Gainsboro
        Me.dataGrid1.BackgroundColor = System.Drawing.Color.DarkGray
        Me.dataGrid1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.dataGrid1.CaptionBackColor = System.Drawing.Color.DarkKhaki
        Me.dataGrid1.CaptionFont = New System.Drawing.Font("Tahoma", 8.0!, System.Drawing.FontStyle.Bold)
        Me.dataGrid1.CaptionForeColor = System.Drawing.Color.Black
        Me.dataGrid1.DataMember = ""
        Me.dataGrid1.FlatMode = True
        Me.dataGrid1.Font = New System.Drawing.Font("Times New Roman", 9.0!)
        Me.dataGrid1.ForeColor = System.Drawing.Color.Black
        Me.dataGrid1.GridLineColor = System.Drawing.Color.Silver
        Me.dataGrid1.HeaderBackColor = System.Drawing.Color.Black
        Me.dataGrid1.HeaderFont = New System.Drawing.Font("Tahoma", 8.0!, System.Drawing.FontStyle.Bold)
        Me.dataGrid1.HeaderForeColor = System.Drawing.Color.White
        Me.dataGrid1.LinkColor = System.Drawing.Color.DarkSlateBlue
        Me.dataGrid1.Location = New System.Drawing.Point(8, 8)
        Me.dataGrid1.Name = "dataGrid1"
        Me.dataGrid1.ParentRowsBackColor = System.Drawing.Color.LightGray
        Me.dataGrid1.ParentRowsForeColor = System.Drawing.Color.Black
        Me.dataGrid1.SelectionBackColor = System.Drawing.Color.Firebrick
        Me.dataGrid1.SelectionForeColor = System.Drawing.Color.White
        Me.dataGrid1.Size = New System.Drawing.Size(344, 152)
        Me.dataGrid1.TabIndex = 3
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(360, 198)
        Me.Controls.Add(Me.btnClose)
        Me.Controls.Add(Me.btnLoad)
        Me.Controls.Add(Me.dataGrid1)
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "People"
        CType(Me.dataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
        Dim conPeople As OdbcConnection = New OdbcConnection("DSN=People;DefaultDir=C:\\Programs\\FunctionX;" & _
                        "DBQ=C:\\Programs\\FunctionX;")

        Dim strSelection As String = "SELECT Persons.* FROM Persons"
        Dim cmdPeople As OdbcCommand = New OdbcCommand(strSelection, conPeople)

        Dim odaPeople As OdbcDataAdapter = New OdbcDataAdapter(cmdPeople)

        Dim dsPersons As DataSet = New DataSet("Persons")
        odaPeople.Fill(dsPersons)

        dataGrid1.DataSource = dsPersons
        dataGrid1.DataMember = dsPersons.Tables.Item(0).TableName

        conPeople.Open()
        conPeople.Close()
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        End
    End Sub
End Class

Home Copyright © 2005-2016, FunctionX