Imports System.Data
Imports C1.C1DataExtender
Imports System.Data.OleDb
Imports System.IO

Public Class Form1

    Private Sub button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click
        ordersDataAdapter.Fill(dataSet1)
        Dim tb As DataTable = dataSet1.Tables("Orders")
        tb.PrimaryKey = New DataColumn() {tb.Columns("OrderID")}
        ordersDataGrid.DataSource = dataSet1
        ordersDataGrid.DataMember = "Orders"
        button2.Enabled = False
    End Sub

    Private Sub button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button3.Click
        ordDetDataAdapter.Fill(dataSet1)
        Dim tb As DataTable = dataSet1.Tables("Order Details")
        tb.PrimaryKey = New DataColumn() {tb.Columns("OrderID"), tb.Columns("ProductID")}
        ordDetDataGrid.DataSource = dataSet1.Tables("Order Details")
        button3.Enabled = False
    End Sub

    Private Sub button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button4.Click
        Dim rel As New DataRelation("Orders - Order Details", _
              dataSet1.Tables("Orders").Columns("OrderID"), _
              dataSet1.Tables("Order Details").Columns("OrderID"))
        dataSet1.Relations.Add(rel)
        button4.Enabled = False
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim csb As New OleDbConnectionStringBuilder(oleDbConnection1.ConnectionString)
        ' If connection string specified in application resources points to a non-existant database file
        ' then use a database from a default sample database location.
        If Not File.Exists(csb.DataSource) Then
            csb.DataSource = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), _
                     "ComponentOne Samples\Common\C1NWind.mdb")
            oleDbConnection1.ConnectionString = csb.ToString()
        End If
    End Sub
End Class
