0

Using Visual Studio 2002 and Microsoft SQL Server. My code does not produce an error, but still the SQL Server table is is still unaffected. :(

The "Add" version of this code works well. . it's just the update. T_T

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

    Try
        ''Open DBase
        dbOpen()
        Dim cmd As New SqlCommand()
        Dim cmdm As New SqlCommand()

        cmd.CommandText = "UPDATE [Currency] SET Country= @Country, Unit= @Unit , Code= @Code WHERE ISO= @ISO"

        Dim paramISO As New SqlParameter()
        paramISO.ParameterName() = "@ISO"
        paramISO.Value() = txtIso.Text
        cmd.Parameters.Add(paramISO)

        Dim paramCountry As New SqlParameter()
        paramCountry.ParameterName() = "@Country"
        paramCountry.Value() = txtCountry.Text
        cmd.Parameters.Add(paramCountry)

        Dim paramUnit As New SqlParameter()
        paramUnit.ParameterName() = "@Unit"
        paramUnit.Value() = txtUnit.Text
        cmd.Parameters.Add(paramUnit)

        Dim paramCode As New SqlParameter()
        paramCode.ParameterName() = "@Code"
        paramCode.Value() = txtCurrencyCode.Text
        cmd.Parameters.Add(paramCode)

        MessageBox.Show("Record Updated! ", "Update Status", MessageBoxButtons.OK, MessageBoxIcon.Information)

    Catch ex As Exception
        MessageBox.Show("Record Not Updated! ", "Update Status", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Finally
        dbClose()
        'refresh data grid
        fillgrid()
        'disable fields
        disControl()
    End Try
End Sub
Dariusz Woźniak
  • 9,640
  • 6
  • 60
  • 73
kinrubich
  • 15
  • 4

1 Answers1

1

You're missing this statement:

cmd.ExecuteNonQuery()  

Add this statement after you've done adding all the parameters to your sqlCommand object.

viclim
  • 959
  • 8
  • 16
  • O_O OMG Thank you very Much! i've already spent 2 hours trying to figure out what's wrong. . LOL Still need to practice. . Still a newbie. . :) – kinrubich Apr 01 '13 at 06:58
  • You're welcome. Practice make perfect. Try to read some tutorial on http://www.codeproject.com/ – viclim Apr 01 '13 at 07:01
  • :) consequence of copy and pasting. . haha i missed the execute line. . I thought there's something wrong in the commandtext. . – kinrubich Apr 01 '13 at 07:05