So I am trying to update a database and a datagridview with a "save" button, I used the part of this code earlier in my program for another function, but here it is giving me a syntax error. Can anyone tell me where? I don't understand where it is.
This part of the code works when I add an employee.
Private Sub AddEmployee_Click(sender As Object, e As EventArgs) Handles AddEmployee.Click
Dim Msg, Style, Title, Response, mystring
Msg = "Do you want to add employee ?"
Style = vbYesNo + vbCritical + vbDefaultButton2
Title = "MsgBox Demonstration"
' Display message.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
TableAdapterManager.UpdateAll(Database13DataSet)
con.Open()
cmd.CommandType = System.Data.CommandType.Text
cmd.CommandText = "Insert INTO dbo.employees (EmpID, LastName, FirstName, AddressHalf, SSN, VehNumb, Certification) values ('" + EmpID.Text + "' , '" + LastName1.Text + "', '" + FirstName1.Text + "', '" + AddyHalf1.Text + "', '" + SocialNum.Text + "', '" + VehNumb.Text + "', '" + Certification1.Text + "')"
cmd.Connection = con
cmd.ExecuteNonQuery()
MessageBox.Show("Employee Added")
Else
mystring = True
MessageBox.Show("Cancelled")
End If
con.Close()
This part of the code is the part that doesn't work. I think it has something to do with my coding trying to update a table but I cannot figure it out.
Private Sub SaveBtn_Click(sender As Object, e As EventArgs) Handles SaveBtn.Click
Dim Msg, Style, Title, Response, mystring
Msg = "Do you want to update employee ?"
Style = vbYesNo + vbCritical + vbDefaultButton2
Title = "MsgBox Demonstration"
' Display message.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
TableAdapterManager.UpdateAll(Database13DataSet)
con.Open()
cmd.CommandType = System.Data.CommandType.Text
cmd.CommandText = "Update employees SET (EmpID, LastName, FirstName, AddressHalf, SSN, VehNumb, Certification) Where ( ModEmpID.Text , ModLastName.Text , ModFirstName.Text, ModAddy.Text , ModSSN.Text , ModVehNum.Text , ModCerts.Text )"
cmd.Connection = con
cmd.ExecuteNonQuery()
MessageBox.Show("Employee Added")
con.Close()
Else
mystring = True
MessageBox.Show("Cancelled")
End If
con.Close()
End Sub
Public Sub Updating()
Me.EmployeesTableAdapter.Fill(Me.Database13DataSet.Employees)
End Sub
End Class