UPDATE语句中的语法错误。通过cmd.nonexecutequery

时间:2015-12-06 04:58:40

标签: vb.net oledb oledbcommand

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()

1 个答案:

答案 0 :(得分:-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& "'" &安培; _

",课程='" &安培; Me.ComboBox3.Text& "'" &安培; _

"在哪里CandidateID =" &安培; Me.TextBox1.Tag

cmd.ExecuteNonQuery()

我的桌子不正确。 谢谢那些回复我的帖子的人