DateTime problem

  • Thread starter Thread starter reidarT
  • Start date Start date
R

reidarT

I got help from Cor L, but is not finished yet.

In a windows form I need to add a date to a table in Access.

Dim dteDato As Date = (Me.txtDato.Text) ' I have tried Value instead of
Text, but it doesn't help
Dim con As New OleDb.OleDbConnection("Provider=Micr.....
Dim cmd As New OleDb.OleDbCommand("INSERT INTO tblToDo ( Dato ) SELECT " &
dteDato, con)
....
The dteDato shows as #6/30/2006#
The table in access has the field as Date, Short date.
The message I get is Syntax error in number in query expression 30.06.2006
(norwegian format)
I can't find ut what's wrong.
reidarT
 
Reidar,

I saw you changed your dateandtime already on your computer,

However can you declare further, is this an insert commando from a
dataadapter or just an insert commando for an executenonquery

Cor
 
I have found the solution.
Dim dteDato As String = (Me.txtDato.Text)
Dim dteDato2 As String = "#" & Mid(dteDato, 4, 2) & "/" &
Mid(dteDato, 1, 2) & "/" & Mid(dteDato, 7, 4) & "#"
Then it works OK
Thanks for your help!
reidarT
 
For formatting the date you could use this:

Dim dteDato As DateTime = DateTime.Parse(Me.txtDato.Text)
Dim dteDato2 As String = dteDato.ToString("#MM/dd/yyyy#")
 
Back
Top