晚上好,
我正在使用下面的代码来更新我的 MySQL 数据库中的值。在运行时,代码一直执行,没有错误,但是,当我查看数据库时,记录没有受到影响。有人可以告诉我我做错了什么吗?谢谢。
我最近自学了如何使用参数,所以也许我做错了——不知道。
这是我的代码:
Private Sub updateCard()
Call encryptCard()
Dim ConnectionString As String = String.Format("Server={0};Port={1};Uid={2};Password={3};Database=accounting", FormLogin.ComboBoxServerIP.SelectedItem, My.Settings.DB_Port, My.Settings.DB_UserID, My.Settings.DB_Password)
Dim myQuery As String = "UPDATE cc_master " & _
"SET ccType = @ccType, ccNumber = @ccNumber, ccExpireMonth = @ccExpireMonth, " & _
"ccExpireYear = @ccExpireYear, ccCode = @ccCode, ccAuthorizedUseStart = @ccAuthorizedUseStart, " & _
"ccAuthorizedUseEnd = @ccAuthorizedUseEnd, ccZipcode = @ccZipcode, dateModified = @dateModified, modifiedBy = @modifiedBy " & _
"WHERE ccID = @ccID"
Using dbConn As New MySqlConnection(ConnectionString)
Using dbComm As New MySqlCommand()
With dbComm
.Connection = dbConn
.CommandType = CommandType.Text
.CommandText = myQuery
.Parameters.AddWithValue("@ccID", ListViewCard.SelectedItems(0).ToString)
.Parameters.AddWithValue("@ccType", ComboBoxCardType.Text)
.Parameters.AddWithValue("@ccNumber", encryptedCard)
.Parameters.AddWithValue("@ccExpireMonth", TextBoxExpireMonth.Text)
.Parameters.AddWithValue("@ccExpireYear", TextBoxExpireYear.Text)
.Parameters.AddWithValue("@ccCode", TextBoxCVV2.Text)
.Parameters.AddWithValue("@ccAuthorizedUseStart", Format(DateTimePickerStartDate.Value, "yyyy-MM-dd HH:MM:ss"))
.Parameters.AddWithValue("@ccAuthorizedUseEnd", Format(DateTimePickerEndDate.Value, "yyyy-MM-dd HH:MM:ss"))
.Parameters.AddWithValue("@ccZipcode", TextBoxZipCode.Text)
.Parameters.AddWithValue("@dateModified", Format(DateTime.Now, "yyyy-MM-dd HH:MM:ss"))
.Parameters.AddWithValue("@modifiedBy", FormLogin.TextBoxUsername.Text)
End With
Try
dbConn.Open()
dbComm.ExecuteNonQuery()
MessageBox.Show("Card info SUCCESSFULLY updated!")
Catch ex As Exception
MessageBox.Show("A DATABASE ERROR HAS OCCURED" & vbCrLf & vbCrLf & ex.Message & vbCrLf & _
vbCrLf + "Please report this to the IT/Systems Helpdesk at Ext 131.")
End Try
End Using
End Using
End Sub