当我收到这个奇怪的错误时,尝试将值输入MySql
到VB
:
"命令执行期间遇到致命错误。"
我已附上以下代码,并且不再使用VB
将input
导入MySql
。
Imports MySql.Data.MySqlClient
Public Class Form1
Dim conn As MySqlConnection
Dim cmd As MySqlCommand
Private Sub ClientBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles ClientBindingNavigatorSaveItem.Click
Me.Validate()
Me.ClientBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.Murpha83_dbDataSet1)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Murpha83_dbDataSet1.client' table. You can move, or remove it, as needed.
Me.ClientTableAdapter.Fill(Me.Murpha83_dbDataSet1.client)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim oForm As Form3
oForm = New Form3()
oForm.Show()
oForm = Nothing
Me.Close()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Dim Reader As MySqlDataReader
Dim Query As String
conn = New MySqlConnection
conn.ConnectionString =
"server=mysql.scss.tcd.ie;user id=murpha83;password=gh8ht6789;database=murpha83_db"
conn.Open()
Query = "INSERT INTO client (client_username, name, address, email, DOB, password, employee) Values (@a, @b, @c, @d, @e, @f, @g)"
cmd = New MySqlCommand(Query, conn)
cmd.Parameters.AddWithValue("@a", clientUsername.Text)
cmd.Parameters.AddWithValue("@b", cusName.Text)
cmd.Parameters.AddWithValue("@c", address.Text)
cmd.Parameters.AddWithValue("@d", email.Text)
cmd.Parameters.AddWithValue("@e", DOB.Text)
cmd.Parameters.AddWithValue("@f", employee.CheckState)
'Dim cmd As New MySqlCommand(("INSERT INTO client VALUES ('" & clientUsername.Text & "', '" & cusName.Text & "', '" & address.Text & "','" & email.Text & "','" & DOB.Text & "''" & employee.CheckState & "')"), conn)
'Reader = cmd.ExecuteReader
cmd.ExecuteNonQuery()
conn.Close()
MsgBox("Success....", MsgBoxStyle.Information, "SUCCESS")
clientUsername.Clear()
cusName.Clear()
address.Clear()
email.Clear()
DOB.Value = Today
employee.Text = "Unchecked"
End Sub
Private Sub cusName_TextChanged(sender As Object, e As EventArgs) Handles cusName.TextChanged
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles clientUsername.TextChanged
End Sub
Private Sub Label7_Click(sender As Object, e As EventArgs) Handles Label7.Click
End Sub
End Class