-1
If Me.TextBox1.Tag & "" = "" Then
    cmd.CommandText = "INSERT INTO Table1(CandidateID, Fname, Mname, Lname, Partylist, Pst, course) " & _
        " VALUES (" & Me.TextBox1.Text & ", '" & Me.TextBox2.Text & "', '" & Me.TextBox3.Text & "', '" & _
        Me.TextBox4.Text & "', '" & Me.ComboBox1.Text & "', '" & Me.ComboBox2.Text & "', '" & Me.ComboBox3.Text & "')"

    cmd.ExecuteNonQuery()
Else
    cmd.CommandText = "UPDATE table " & _
    " SET CandidateID=" & Me.TextBox1.Text & _
    ", Fname='" & Me.TextBox2.Text & "'" & _
    ", Mname='" & Me.TextBox3.Text & "'" & _
    ", Lname='" & Me.TextBox4.Text & "'" & _
    ", Partylist='" & Me.ComboBox1.Text & "'" & _
    ", Pst='" & Me.ComboBox2.Text & "'" & _
    ", Course='" & Me.ComboBox3.Text & "'" & _
    " WHERE CandidateID=" & Me.TextBox1.Tag

    cmd.ExecuteNonQuery()
Han
  • 3,052
  • 2
  • 22
  • 31
  • i cant find the error of my statement. – namelessaccount Dec 06 '15 at 04:59
  • 2
    What's your table name? `Table1` or `Table`? If you use `table` as your table name, you should use brackets when accessing it, because `table` is a reserved word. Example: UPDATE [Table] SET ... and so on. – Han Dec 06 '15 at 08:07
  • the name of my table is Table1 and that was my error all along. thank you. – namelessaccount Dec 06 '15 at 08:18
  • Apparently there is no syntax error in UPDATE query. I think the values you are passing may cause some error. I have observed one thing that also may cause error. You are updating CandidateID with TextBox1.Text and at the same time you are using same field in WHERE clause but comparing with TextBox1.Tag. Is there any specific reason for this??? One more thing in INSERT query table name is Table1 while in UPDATE query table name is just "table" this is also an error. – Muhammad Irfan Azam Dec 06 '15 at 22:50

1 Answers1

-1

cmd.CommandText = "UPDATE Table1 " & _

" SET CandidateID=" & Me.TextBox1.Text & _

", Fname='" & Me.TextBox2.Text & "'" & _

", Mname='" & Me.TextBox3.Text & "'" & _

", Lname='" & Me.TextBox4.Text & "'" & _

", Partylist='" & Me.ComboBox1.Text & "'" & _

", Pst='" & Me.ComboBox2.Text & "'" & _

", Course='" & Me.ComboBox3.Text & "'" & _

" WHERE CandidateID=" & Me.TextBox1.Tag

cmd.ExecuteNonQuery()

my table was incorrect. thank you for those who replied to my thread