I created a program for our Thesis which uses MySQL server for record keeping. all functions (delete, save, add) are working except the UPDATE. When clicking the UPDATE button, the UPDATED RECORD replace all recently added records and duplicates all of the records on the datagrid.
newpatient
is mysql table
PatientManagementSystem
is name of the Database
Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
MySqlConn = New MySqlConnection
MySqlConn = New MySqlConnection("server=localhost;user id=root;password=root;database=PatientManagementSystem;")
MySqlConn.Open()
Dim cmd As MySqlCommand = MySqlConn.CreateCommand
cmd.CommandText = String.Format("UPDATE newpatient SET " &
"Lastname='{0}', " &
"Firstname= '{1}', " &
"Middlename= '{2}', " &
"Age= '{3}', " &
"Gender= '{4}', " &
"Address= '{5}', " &
"Occupation= '{6}', " &
"Month= '{7}', " &
"Day= '{8}', " &
"Year= '{9}'",
txtFirstname.Text,
txtFirstname.Text,
txtMiddlename.Text,
txtAge.Text,
cmbGender.SelectedItem,
txtAddress.Text,
txtOccupation.Text,
cmbMonth.SelectedItem,
cmbDay.SelectedItem,
cmbYear.SelectedItem)
Dim affectedRows As Integer = cmd.ExecuteNonQuery
If affectedRows > 0 Then
MsgBox("Record successfully updated!", MsgBoxStyle.Information, "Success")
Else
MsgBox("Updating record failed.", MsgBoxStyle.Critical, "Failed")
End If
MySqlConn.Close()