0

i can't get DateTimePicker to insert into Access databse. I've tried all the suggestion i can find from this forum, so i'm thinking my problem is different?

my table has a column date which has a Date/Time format

my code

Dim cmd As OleDbCommand
            Dim sqlstr As String, ans As Boolean
            Dim mydate As DateTime
            mydate = Me.dtPickerT.Value

            sqlstr = "INSERT INTO table(date) VALUES (" & mydate & ")"
            cmd = New OleDbCommand(sqlstr, con)


            ans = cmd.ExecuteNonQuery()

            If (ans = True) Then
                'message added
                MsgBox("success")
            Else
                MsgBox("not entered")   '' error
            End If
            cmd = Nothing

error message is: Syntax error in INSERT INTO statement. - Micorsoft Office Access Database Engine

the query returned by cmd is: INSERT INTO taken(date) VALUES (1/8/2012)

what did i do wrong?? Pls help :D

i'v even tried (#" & mydate & "#) and (" & dtPickerT.Value.ToString & ") etc :(

6
Contributors
6
Replies
29
Views
5 Years
Discussion Span
Last Post by izzah_3
0

oh sorry guys, my bad :(

i was too careless... date seems to be a reserve words, so [date] fix the problem.

sorry again

0

Hi buddy!
It was good that you did not remmove this post. I found my answer here! I was wondering on how to actually insert datetime to access from VB date time picker. If you meet one person today, tell him/her that "We learn through others' mistakes".
Stay well!

0

is this for microsoft visual 2010?

by the way, does anybody knows how to link the date time picker and combobox microsoft visual studio 2010 to access database? I just really dont know.

help much appreciated

0

kindly tell me how we update time automatically in inline database in android..?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.