Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting a date into an access database.

Status
Not open for further replies.

qwert231

Programmer
Sep 4, 2001
756
US
Here is my code:
Code:
Dim con As New OleDb.OleDbConnection(comFunc.dbInt)
Dim com As New OleDb.OleDbCommand("INSERT INTO tblItems( Date , Body ) VALUES ( ? , ? )", con)
Dim pc As OleDb.OleDbParameterCollection = com.Parameters
pc.Add("Date", Data.OleDb.OleDbType.Date).Value = CType(Me.tbNewDate.Text, Data.OleDb.OleDbType.Date).Date
pc.Add("Body", Data.OleDb.OleDbType.LongVarWChar).Value = Me.tbBody.Text '.Value = Me.tbBody.Text

con.Open()
Try
 com.ExecuteNonQuery()
Catch er As Exception
 Me.errs.Text += er.ToString & &quot;<br />&quot;
End Try
con.Close()

And I get an 'Syntax error in INSERT INTO statement.' error as my Exception. Can anybody tell me why?

I am trying a date that looks like 2/12/2003 in the textbox. The fields in the database are NewsID (Autonumber), Date (Date/Time), and Body (Memo).

Can't figure out what is wrong.
 
Correction, the CType value I am trying for the Date looks like this:
CType(Me.tbNewDate.Text, Date).Date
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top