我現在不是爲什麼該方法在if語句中被跳過任何人都可以幫我解決這個問題嗎?更新查詢正在跳過if語句vb.net
這裏的更新SQL查詢
Public Sub Edituser()
conn()
dbconn.Open()
sql = "UPDATE player SET First [email protected] Last [email protected], [email protected], Date of [email protected], Civil [email protected], [email protected], [email protected], [email protected] WHERE ID = " + TextBox8.Text + ""
Try
dbcomm = New MySqlCommand(sql, dbconn)
dbcomm.Parameters.Add(New MySqlParameter("@1", TextBox1.Text))
dbcomm.Parameters.Add(New MySqlParameter("@2", TextBox2.Text))
dbcomm.Parameters.Add(New MySqlParameter("@3", TextBox9.Text))
dbcomm.Parameters.Add(New MySqlParameter("@4", TextBox3.Text))
dbcomm.Parameters.Add(New MySqlParameter("@5", TextBox4.Text))
dbcomm.Parameters.Add(New MySqlParameter("@6", TextBox5.Text))
dbcomm.Parameters.Add(New MySqlParameter("@7", TextBox6.Text))
dbcomm.Parameters.Add(New MySqlParameter("@8", TextBox7.Text))
dbread = dbcomm.ExecuteReader()
dbread.Close()
MsgBox("Successfully updated!")
Catch ex As Exception
Finally
dbconn.Close()
End Try
End Sub
和這裏的if語句
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Or TextBox6.Text = "" Or TextBox7.Text = "" Or TextBox9.Text = "" Then
MsgBox("Please complete all the fields")
Else
Dim result As Integer = MessageBox.Show("Are you sure you want to Edit the information?", "Update", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
If result = DialogResult.OK Then
Edituser()
MsgBox(" Player information Updated!")
Me.Close()
Player.Show()
End If
End If
End Sub
在此先感謝。
你永遠不應該通過串聯把一個用戶輸入您的查詢。這使得它易於進行sql注入。通過使用set部件中的參數,您處於正確的軌道上。 – Peter
你應該學習如何使用調試器。如果你的if語句被輸入,它會調用'EditUser()'方法,正如在Rahuls中發佈的,你的問題似乎與'EditUser()'方法中的語法一樣。而不是調用該方法的if語句。 – Kevin
至少顯示ex.Message到MessageBox或Debug.Writeline(),以便您可以看到您的語句出了什麼問題。 –