Imports System.Data.SqlClient
Public Class EX2
    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 GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
    Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
    Friend WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
    Friend WithEvents SqlCommand1 As System.Data.SqlClient.SqlCommand
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.RadioButton1 = New System.Windows.Forms.RadioButton
        Me.RadioButton2 = New System.Windows.Forms.RadioButton
        Me.ListBox1 = New System.Windows.Forms.ListBox
        Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection
        Me.SqlCommand1 = New System.Data.SqlClient.SqlCommand
        Me.GroupBox1.SuspendLayout()
        Me.SuspendLayout()
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.RadioButton2)
        Me.GroupBox1.Controls.Add(Me.RadioButton1)
        Me.GroupBox1.Location = New System.Drawing.Point(24, 16)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(112, 104)
        Me.GroupBox1.TabIndex = 0
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "Country"
        '
        'RadioButton1
        '
        Me.RadioButton1.Location = New System.Drawing.Point(16, 24)
        Me.RadioButton1.Name = "RadioButton1"
        Me.RadioButton1.Size = New System.Drawing.Size(80, 24)
        Me.RadioButton1.TabIndex = 0
        Me.RadioButton1.Text = "Usa"
        '
        'RadioButton2
        '
        Me.RadioButton2.Location = New System.Drawing.Point(16, 64)
        Me.RadioButton2.Name = "RadioButton2"
        Me.RadioButton2.Size = New System.Drawing.Size(80, 24)
        Me.RadioButton2.TabIndex = 1
        Me.RadioButton2.Text = "uk"
        '
        'ListBox1
        '
        Me.ListBox1.Location = New System.Drawing.Point(8, 144)
        Me.ListBox1.Name = "ListBox1"
        Me.ListBox1.Size = New System.Drawing.Size(344, 95)
        Me.ListBox1.TabIndex = 1
        '
        'SqlConnection1
        '
        Me.SqlConnection1.ConnectionString = "workstation id=INSTRUCTOR12;packet size=4096;integrated security=SSPI;data source" & _
        "=""(local)"";persist security info=False;initial catalog=Northwind"
        '
        'SqlCommand1
        '
        Me.SqlCommand1.CommandText = "SELECT FirstName, LastName, HireDate, Country FROM emp WHERE (Country = @c)"
        Me.SqlCommand1.Connection = Me.SqlConnection1
        Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@c", System.Data.SqlDbType.NVarChar, 15, "Country"))
        '
        'EX2
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(376, 266)
        Me.Controls.Add(Me.ListBox1)
        Me.Controls.Add(Me.GroupBox1)
        Me.Name = "EX2"
        Me.Text = "EX2"
        Me.GroupBox1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
        ListBox1.Items.Clear()
        Dim r As SqlDataReader
        If RadioButton1.Checked = True Then
            Try
                SqlCommand1.Parameters("@c").Value = RadioButton1.Text
                SqlConnection1.Open()
                r = SqlCommand1.ExecuteReader
                Do While r.Read
                    ListBox1.Items.Add(r.GetValue(0) & vbTab & r.GetValue(1) & vbTab & r.GetValue(2) & vbTab & r.GetValue(3))
                Loop
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            Finally
                r.Close()
                SqlConnection1.Close()
            End Try
        End If
    End Sub

    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
        ListBox1.Items.Clear()
        Dim r As SqlDataReader
        If RadioButton2.Checked = True Then
            Try
                SqlCommand1.Parameters("@c").Value = RadioButton2.Text
                SqlConnection1.Open()
                r = SqlCommand1.ExecuteReader
                Do While r.Read
                    ListBox1.Items.Add(r.GetValue(0) & vbTab & r.GetValue(1) & vbTab & r.GetValue(2) & vbTab & r.GetValue(3))
                Loop
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            Finally
                r.Close()
                SqlConnection1.Close()
            End Try
        End If
    End Sub
End Class
