Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
855 views
in Technique[技术] by (71.8m points)

insert into syntax error vb.net and access database

i keep getting a syntax error for the cmd code and i dont understand whats wrong, i have checked online everywhere but i cant seem to find a solutiom. This is the error "syntax error in INSERT INTO statement"

pro = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:UsershifzuDesktopCS A LEVELHolidayPlansHolidayPlansHPlansDB.accdb"
    connstring = pro
    myconnection.ConnectionString = connstring
    myconnection.Open()
    Dim cmd As New OleDb.OleDbCommand("INSERT INTO User Information ([Forename],[Surname],[DOB],[MobileNO],[Email Address]) VALUES ('" & TextBoxForename.Text & "','" & TextBoxSurname.Text & "','" & TextBoxAge.Text & "','" & TextBoxContactNO.Text & "','" & TextBoxEmail.Text & "')", myconnection)
    cmd.Parameters.Add(New OleDbParameter("Forename", CType(TextBoxForename.Text, String)))
    cmd.Parameters.Add(New OleDbParameter("Surname", CType(TextBoxSurname.Text, String)))
    cmd.Parameters.Add(New OleDbParameter("DOB", CType(TextBoxAge.Text, String)))
    cmd.Parameters.Add(New OleDbParameter("MobileNO", CType(TextBoxContactNO.Text, String)))
    cmd.Parameters.Add(New OleDbParameter("Email Address", CType(TextBoxEmail.Text, String)))

    Try
        cmd.ExecuteNonQuery()
        cmd.Dispose()
        myconnection.Close()
        MsgBox("Info Saved", MsgBoxStyle.Information, "Successfully Added!")
        TextBoxForename.Clear()
        TextBoxSurname.Clear()
        TextBoxAge.Clear()
        TextBoxContactNO.Clear()
        TextBoxEmail.Clear()
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...