vb Syntax error in INSERT INTO statement

Posted by user201806 on Stack Overflow See other posts from Stack Overflow or by user201806
Published on 2012-11-11T10:49:22Z Indexed on 2012/11/11 11:00 UTC
Read the original article Hit count: 230

Filed under:
|

im new in vb, i was create a program to connection ms access but when i run the program it get syntax error in Insert into statement, OleDbExpection was unhandled

here my code

Public Class Form2
Dim cnn As New OleDb.OleDbConnection
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    txtdate.Value = DateTime.Now
    cnn = New OleDb.OleDbConnection
    cnn.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0; Data Source=C:\Users\John\Documents\db.mdb"
End Sub
Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
    If Not cnn.State = ConnectionState.Open Then
        cnn.Open()

    End If
    Dim cmd As New OleDb.OleDbCommand

    cmd.Connection = cnn
    cmd.CommandText = "INSERT INTO sr(names,add,tel,dates,prob,serv,model,snm,acc,sna,remark)" & _
                          "VALUES ('" & Me.txtname.Text & "','" & Me.txtadd.Text & "','" & Me.txttel.Text & "', '" & _
                          Me.txtdate.Text & "','" & Me.txtpro.Text & "','" & Me.txtser.Text & "','" & Me.txtmod.Text & "', '" & _
                          Me.txtsnm.Text & "','" & Me.txtacc.Text & "','" & Me.txtsna.Text & "','" & Me.txtrem.Text & "')"

    cmd.ExecuteNonQuery()

    cnn.Close()
End Sub

End Class

it's there any wrong with my code?

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about syntax-error