0
使用Visual Studio 2002和Microsoft SQL Server。我的代碼不會產生錯誤,但SQL Server表仍然不受影響。 :(無法更新VB.NET中的SQL Server表格
這段代碼的 「添加」 版本運行良好,它只是更新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
O_O OMG非常感謝你!我已經花了2個小時試圖弄清楚什麼是錯誤。LOL還是需要練習......還是一個新手......: ) – kinrubich
不客氣。實踐使完美。嘗試閱讀一些教程http://www.codeproject.com/ – viclim
:)複製和粘貼的後果。 。哈哈我錯過了執行線。 。我認爲commandtext中有錯誤。 。 – kinrubich