Imports System.Data.SqlClient

Public Class TestForm
    Private Sub Update_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpdateDB.Click
        ' Create connection.
        Dim Connect As String = My.Settings.Northwind
        Dim con As New SqlConnection(Connect)
        con.Open()

        ' Create a silly update command.
        Dim SQL As String = "UPDATE Orders SET ShipCountry='Oceania' " & _
          "WHERE OrderID='10248'"
        Dim cmd As New SqlCommand(SQL, con)

        ' Execute the command.
        Dim NumAffected As Integer
        NumAffected = cmd.ExecuteNonQuery()

        con.Close()

        ' Display the number of affected records.
        MessageBox.Show(NumAffected.ToString & " records updated", "Results", _
          MessageBoxButtons.OK)


    End Sub

    Private Sub cmdInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdInsert.Click

        ' Create connection.
        Dim Connect As String = My.Settings.Northwind
        Dim con As New SqlConnection(Connect)
        con.Open()

        Dim cmd As New SqlCommand("AddNewCustomer", con)
        cmd.CommandType = CommandType.StoredProcedure

        ' Create an SqlParameter object. We don't use the New keyword here because this
        ' object will only be used to hold a reference to the parameter created with
        ' the Command object.
        Dim param As SqlParameter

        param = cmd.Parameters.AddWithValue("@CustomerID", "*TEST")
        param = cmd.Parameters.AddWithValue("@CompanyName", "No Starch Press")
        param = cmd.Parameters.AddWithValue("@ContactName", "Matthew MacDonald")

        Dim NumAffected As Integer
        NumAffected = cmd.ExecuteNonQuery()


        con.Close()

        ' Display the number of affected records.
        MessageBox.Show(NumAffected.ToString & " records inserted", "Results", _
          MessageBoxButtons.OK)

    End Sub

    Private Sub cmdParameterized_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdParameterized.Click

        ' Create connection.
        Dim Connect As String = My.Settings.Northwind
        Dim con As New SqlConnection(Connect)
        con.Open()

        ' Define the parameterized command.
        Dim SQL As String = _
          "UPDATE Orders SET ShipCountry=@ShipCountry WHERE OrderID=@OrderID"
        Dim cmd As New SqlCommand(SQL, con)
        ' Add the parameters.
        cmd.Parameters.AddWithValue("@ShipCountry", "Oceania")
        cmd.Parameters.AddWithValue("@OrderID", 10248)

        ' Execute the command.
        Dim NumAffected As Integer
        NumAffected = cmd.ExecuteNonQuery()
        con.Close()

        ' Display the number of affected records.
        MessageBox.Show(NumAffected.ToString & " records inserted", "Results", _
          MessageBoxButtons.OK)

    End Sub
End Class