Error adding new records to table (OleDb)
Ok... All I'm trying to do is add a record to the database and it's giving me a "Syntax Error in INSERT TO statement"
The tbl_Guestbook_Entries table has 5 fields:
ID - AutoNumber
Date - String
Name - String
Email - String
Message - String
Here's the code:
Code:
' setup connection and command
Dim dbCon As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
Server.MapPath("~/Guestbook.mdb"))
Dim dbCmd As New OleDbCommand("INSERT INTO tbl_Guestbook_Entries (Date,Name,Email,Message) VALUES ('" & _
DateTime.Now.Date.ToString().Substring(0, 10) & "','" & txtName.Text & "','" & txtEmail.Text & _
"','" & txtMessage.Text & "')", dbCon)
' execute query to add new record (guestbook entry)
dbCmd.Connection.Open()
dbCmd.ExecuteNonQuery()
dbCmd.Connection.Close()
' clear text fields
txtName.Text = ""
txtEmail.Text = ""
txtMessage.Text = ""
' display guestbook entries
FillMessageTable()
I'm pretty sure the syntax of my INSERT TO statement is correct... Anyone see what's causing the problem?