DateTime problem

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
 
C

Cor Ligthert [MVP]

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
 
R

reidarT

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
 
C

Chris Chilvers

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#")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top