TROUBLE Inserting dat into access database

I am having some trouble inserting a date into a access database, I have tried sever different ways but always get something like - cannot change date to an integer.

Dim theOleDbCommandAsNew OleDb.OleDbCommand("INSERT INTO DATASHEET ([TODATE], ACCESSUSER,DEPTID,TOWN) VALUES (?, ?, ?, ?)")

theOleDbCommand.Connection =New OleDb.OleDbConnection(connectionString)

Dim p0AsNew OleDbParameter("@p0",Me.TODAYSDATE.ToString)

p0.Value =Me.TODAYSDATE.ToString

theOleDbCommand.Parameters.Add(p0)

Dim p1AsNew OleDbParameter("@p1",Me.theUserNameOnly)

p1.Value =Me.theUserNameOnly

theOleDbCommand.Parameters.Add(p1)

Dim p2AsNew OleDbParameter("@p2", OleDbType.Integer,Me.deptid)

p2.Value =Me.deptid

theOleDbCommand.Parameters.Add(p2)

Dim p3AsNew OleDbParameter("@p3", OleDbType.Integer,Me.townid)

p3.Value =Me.townid

theOleDbCommand.Parameters.Add(p3)

'End Inserting

Try

theOleDbCommand.Connection.Open()

theOleDbCommand.ExecuteNonQuery()

theOleDbCommand.Connection.Close()

theOleDbCommand.Parameters.Clear()

Catch

MsgBox("NOPE SOMETHING WENT WRONG WITH THE INSERT", ,"CHECK THE DATABASE!")

EndTry

[3341 byte] By [nhaas] at [2007-12-28]
# 1

:-)

change this:

Dim p0 As New OleDbParameter("@p0", Me.TODAYSDATE.ToString)

p0.Value = Me.TODAYSDATE.ToString

to this:

Dim p0 As New OleDbParameter("@p0", OleDbType.Date, 8)

p0.Value = Me.TODAYSDATE

and thats it! I hope "TODAYSDATE" is a datetime object?

alternatively you could try this:

Dim p0 As New OleDbParameter("@p0", Me.TODAYSDATE)

ahmedilyas at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2

OK I did the:

Dim p0 As New OleDbParameter("@p0", OleDbType.Date, 8)

p0.Value = Me.TODAYSDATE

and get 39091 inserted into the database

for TODAYSDATE I have

Dim TODAYSDATE = Date.Today()

I am not sure if this is what I should have set.

alternatively you could try this:

Dim p0 As New OleDbParameter("@p0", Me.TODAYSDATE) " I get an error on this.

nhaas at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3

what type is the object TODAYSDATE ?

and what error do you get also?

ahmedilyas at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4

I actually boob, it was a problem with the database, once I set it to date/time it actually works! hmm go figure!!!!!

thanks for the help

nhaas at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 5
hehe no worries ;-)
ahmedilyas at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...