这个问题属于这个按钮下,我在这里得到的错误:
objcommand.ExecuteNonQuery()
一旦我按下这个按钮,它应该更新我的MySQL数据库中的所有记录。 这里是我的代码(确切的代码工作正常,另一个表):
Private Sub btnModify1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnModify1.Click
Using objconnection = New MySqlConnection("Server=localhost;database=ba-solutions;user id=root;password=")
objconnection.Open()
If Len(cbxCompanyName.Text) < 1 Then
MsgBox("Please select a company name")
Return
End If
If Len(txtPosition.Text) < 1 Then
MsgBox("Please enter the postion of the shareholder in the company")
Return
End If
If Len(txtNI.Text) <> 8 Then
MsgBox("The National Insurance Number must be 8 characters")
Return
End If
If Len(txtAddressLine.Text) < 1 Then
MsgBox("Enter a First Line of Address")
Return
End If
If Len(txtCity.Text) < 1 Then
MsgBox("Enter a City Name")
Return
End If
If Len(txtPostcode.Text) < 1 Then
MsgBox("Enter a Postcode")
Return
End If
If Len(txtEmail.Text) < 1 Then
MsgBox("Enter an Email Address")
Return
End If
If Len(txtPhoneNumber.Text) <> 11 Then
MsgBox("The Phone Number must be 11 numbers ")
Return
End If
'all validations for relevant textboxes
Dim companyname As String
Dim position As String
Dim ninumber As String
Dim dob As String
Dim forename As String
Dim surname As String
Dim addressline1 As String
Dim city As String
Dim postcode As String
Dim phonenumber As String
Dim email As String
postcode = txtPostcode.Text
companyname = cbxCompanyName.Text
position = txtPosition.Text
ninumber = txtNI.Text
dob = DTP1.Value
forename = txtForename.Text
surname = txtSurname.Text
addressline1 = txtAddressLine.Text
city = txtCity.Text
phonenumber = txtPhoneNumber.Text
email = txtEmail.Text
sqlstring = "UPDATE shareholder_details SET position=@position, ni=@ninumber, dob=@dob, forename=@forename, surname=@surname, addressline1=@addressline, city=@city, postcode=@postcode, phonenumber=@phone, email=@email where companyname= @company "
objcommand = New MySqlCommand(sqlstring, objconnection)
objcommand.Parameters.AddWithValue("@company", companyname)
objcommand.Parameters.AddWithValue("@postion", position)
objcommand.Parameters.AddWithValue("@ni", ninumber)
objcommand.Parameters.AddWithValue("@dob", dob)
objcommand.Parameters.AddWithValue("@forename", forename)
objcommand.Parameters.AddWithValue("@surname", surname)
objcommand.Parameters.AddWithValue("@addressline", addressline1)
objcommand.Parameters.AddWithValue("@city", city)
objcommand.Parameters.AddWithValue("@postcode", postcode)
objcommand.Parameters.AddWithValue("@phone", phonenumber)
objcommand.Parameters.AddWithValue("@email", email)
objcommand.ExecuteNonQuery()
btnRefresh.PerformClick()
Dim check As Integer = objcommand.ExecuteReader.RecordsAffected
If check < 1 Then
MessageBox.Show("Record was not updated, please try again", "Update unsucessfull",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
MessageBox.Show("Record updated sucessfully", "Update sucessfull",
MessageBoxButtons.OK, MessageBoxIcon.Information)
objconnection.Close()
End If
End Using
End Sub