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 C1SchemaDef1 As C1.Data.C1SchemaDef
    Friend WithEvents C1DataSet1 As C1.Data.C1DataSet
    Friend WithEvents button2 As System.Windows.Forms.Button
    Friend WithEvents button1 As System.Windows.Forms.Button
    Friend WithEvents textBox1 As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
        Me.C1SchemaDef1 = New C1.Data.C1SchemaDef
        Me.C1DataSet1 = New C1.Data.C1DataSet
        Me.button2 = New System.Windows.Forms.Button
        Me.button1 = New System.Windows.Forms.Button
        Me.textBox1 = New System.Windows.Forms.TextBox
        CType(Me.C1SchemaDef1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.C1DataSet1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'C1SchemaDef1
        '
        Me.C1SchemaDef1.DataObjectsAssemblyFlags = CType((C1.Data.DataObjectsAssemblyFlags.DataSetNamespaces Or C1.Data.DataObjectsAssemblyFlags.StaticNameFields), C1.Data.DataObjectsAssemblyFlags)
        Me.C1SchemaDef1.DummyImage = CType(resources.GetObject("C1SchemaDef1.DummyImage"), System.Drawing.Bitmap)
        Me.C1SchemaDef1.SerializedSchemaXML = Me.C1SchemaDef1.GetSchemaFromResources(resources, "C1SchemaDef1", Me)
        Me.C1SchemaDef1.SerializedDesignTimeOptionsXML = Me.C1SchemaDef1.GetDesignTimeOptionsFromResources(resources, "C1SchemaDef1", Me)
        '
        'C1DataSet1
        '
        Me.C1DataSet1.BindingContextCtrl = Me
        Me.C1DataSet1.DataLibrary = ""
        Me.C1DataSet1.DataLibraryUrl = ""
        Me.C1DataSet1.DataSetDef = "DataSet"
        Me.C1DataSet1.Locale = New System.Globalization.CultureInfo("en-US")
        Me.C1DataSet1.Name = "C1DataSet1"
        Me.C1DataSet1.SchemaClassName = ""
        Me.C1DataSet1.SchemaDef = Me.C1SchemaDef1
        '
        'button2
        '
        Me.button2.Location = New System.Drawing.Point(368, 150)
        Me.button2.Name = "button2"
        Me.button2.Size = New System.Drawing.Size(112, 24)
        Me.button2.TabIndex = 5
        Me.button2.Text = "Connect to db2"
        '
        'button1
        '
        Me.button1.Location = New System.Drawing.Point(152, 150)
        Me.button1.Name = "button1"
        Me.button1.Size = New System.Drawing.Size(112, 24)
        Me.button1.TabIndex = 4
        Me.button1.Text = "Connect to db1"
        '
        'textBox1
        '
        Me.textBox1.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.C1DataSet1, "Table1.TEXT", True))
        Me.textBox1.Location = New System.Drawing.Point(152, 78)
        Me.textBox1.Name = "textBox1"
        Me.textBox1.Size = New System.Drawing.Size(328, 20)
        Me.textBox1.TabIndex = 3
        Me.textBox1.Text = "textBox1"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(632, 253)
        Me.Controls.Add(Me.button2)
        Me.Controls.Add(Me.button1)
        Me.Controls.Add(Me.textBox1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        CType(Me.C1SchemaDef1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.C1DataSet1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region

    Private Sub SetConnection(ByVal dbName As String)
        C1DataSet1.DynamicConnections.Clear()
        Dim conn As C1.Data.SchemaObjects.Connection = CType(C1DataSet1.Schema.Connections("Connection").Clone(), C1.Data.SchemaObjects.Connection)
        Dim dbPath As String = Application.StartupPath + "\..\..\Data\" + dbName
        conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dbPath
        C1DataSet1.DynamicConnections.Add(conn)
    End Sub

    Private Sub C1DataSet1_BeforeFill(ByVal sender As Object, ByVal e As C1.Data.FillEventArgs) Handles C1DataSet1.BeforeFill
        If C1DataSet1.DynamicConnections.Count = 0 Then SetConnection("db1.mdb")
    End Sub

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        SetConnection("db1.mdb")
        C1DataSet1.Fill()
    End Sub

    Private Sub button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click
        SetConnection("db2.mdb")
        C1DataSet1.Fill()
    End Sub
End Class
