- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
大家晚上好
我正在使用以下内容尝试更新我的 MySQL 数据库中的记录,但记录没有更新,我也没有捕获到任何异常。非常感谢您的帮助:
dbConn = New MySqlConnection("Server=" & FormLogin.ComboBoxServerIP.SelectedItem & ";Port=3306;Uid=trojan;Password=horse;Database=accounting")
Try
If dbConn.State = ConnectionState.Open Then
dbConn.Close()
Else
Try
dbConn.Open()
Dim dbAdapter As New MySqlDataAdapter("UPDATE customer " & _
"SET accountNumber= '" & TextBoxAccount.Text & "', nameLAST='" & TextBoxLastName.Text & "', nameFIRST='" & TextBoxFirstName.Text & "'" & _
"nameSALUTATION='" & ComboBoxSalutation.SelectedItem & "', nameCOMPANY='" & TextBoxCompanyName.Text & "', addressSTREET='" & TextBoxAddress1.Text & "'" & _
"addressSTREET1='" & TextBoxAddress2.Text & "', addressCITY='" & TextBoxCity.Text & "', addressSTATE='" & ComboBoxState.SelectedItem & "'" & _
"addressZIPCODE='" & MaskedTextBoxZip.Text & "', phone='" & MaskedTextBoxPhone.Text & "', fax='" & MaskedTextBoxFax.Text & "', email='" & TextBoxEmail.Text & "'" & _
"WHERE accountNumber='" & TextBoxAccount.Text & "';", dbConn)
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
MessageBox.Show("Customer account SUCCESSFULLY updated!")
Call lockForm()
End If
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
Call lockForm()
dbConn.Close()
最佳答案
使用 MySQLCommand
而不是 MySQLDataAdapter
。您正在破坏使用 ADONet 的目的,因为您的代码仍然容易受到 sql 注入(inject)的攻击。使其参数化。以下是您的代码中的修改代码。它使用 Using-End Using
来正确处理对象处置。
Dim ConnectionString As String ="Server=" & FormLogin.ComboBoxServerIP.SelectedItem & ";Port=3306;Uid=trojan;Password=horse;Database=accounting"
Dim iQuery As String = "UPDATE customer " & _
"SET accountNumber = @accountNumber, nameLAST = @nameLAST, nameFIRST = @nameFIRST, " & _
" nameSALUTATION = @nameSALUTATION, nameCOMPANY = @nameCOMPANY, addressSTREET = @addressSTREET, " & _
" addressSTREET1 = @addressSTREET1, addressCITY = @addressCITY, addressSTATE = @addressSTATE, " & _
" addressZIPCODE = @addressZIPCODE, phone = @phone, fax = @fax, email = @email " & _
"WHERE accountNumber = @accountNumber"
Using dbConn As New MySqlConnection(ConnectionString)
Using dbComm As New MySQLCommand()
With dbComm
.Connection = dbConn
.CommandType = CommandType.Text
.CommandText = iQuery
.Parameters.AddWithValue("@accountNumber", TextBoxAccount.Text )
.Parameters.AddWithValue("@nameLAST", TextBoxLastName.Text)
.Parameters.AddWithValue("@nameFIRST", TextBoxFirstName.Text)
.Parameters.AddWithValue("@nameSALUTATION", ComboBoxSalutation.SelectedItem)
.Parameters.AddWithValue("@nameCOMPANY", TextBoxCompanyName.Text)
.Parameters.AddWithValue("@addressSTREET", TextBoxAddress1.Text)
.Parameters.AddWithValue("@addressSTREET1", TextBoxAddress2.Text)
.Parameters.AddWithValue("@addressCITY", TextBoxCity.Text)
.Parameters.AddWithValue("@addressSTATE", ComboBoxState.SelectedItem)
.Parameters.AddWithValue("@addressZIPCODE", MaskedTextBoxZip.Text)
.Parameters.AddWithValue("@phone", MaskedTextBoxPhone.Text)
.Parameters.AddWithValue("@fax", MaskedTextBoxFax.Text)
.Parameters.AddWithValue("@email", TextBoxEmail.Text)
End With
Try
dbConn.Open
dbComm.ExecuteNonQuery()
MessageBox.Show("Customer account SUCCESSFULLY updated!")
Call lockForm()
Catch( ex as MySQLException)
MessageBox.Show("A DATABASE ERROR HAS OCCURED" & vbCrLf & vbCrLf & ex.Message & vbCrLf & _
vbCrLf + "Please report this to the IT/Systems Helpdesk at Ext 131.")
Finally
dbConn.Close()
End Try
End Using
End Using
关于mysql - 是什么导致我的 UPDATE 语句不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12415682/
今天有小伙伴给我留言问到,try{...}catch(){...}是什么意思?它用来干什么? 简单的说 他们是用来捕获异常的 下面我们通过一个例子来详细讲解下
我正在努力提高网站的可访问性,但我不知道如何在页脚中标记社交媒体链接列表。这些链接指向我在 facecook、twitter 等上的帐户。我不想用 role="navigation" 标记这些链接,因
说现在是 6 点,我有一个 Timer 并在 10 点安排了一个 TimerTask。之后,System DateTime 被其他服务(例如 ntp)调整为 9 点钟。我仍然希望我的 TimerTas
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我就废话不多说了,大家还是直接看代码吧~ ? 1
Maven系列1 1.什么是Maven? Maven是一个项目管理工具,它包含了一个对象模型。一组标准集合,一个依赖管理系统。和用来运行定义在生命周期阶段中插件目标和逻辑。 核心功能 Mav
我是一名优秀的程序员,十分优秀!