Date/Time Strange Problem

S

Shapper

Hello,

I am having an error when inserting a record in an Access database.

The field [publication_date] is of Date/Time type.

This is my query and the parameters for that field:

Dim queryString As String = "INSERT INTO [t_news] ([title], [text],
[publication_date]) VALUES (@title, @text, @publication_date)"

Dim dbCommand As IDbCommand = New OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

With dbCommand.Parameters
.Add(New OleDbParameter("@title", "sample"))
.Add(New OleDbParameter("@text", "sample"))
.Add(New OleDbParameter("@publication_date", DateTime.Now))
End With

I get the error "Data type mismatch in criteria expression."

What is wrong here?

Thanks,
Miguel
 
B

bhawin13

I think you are getting error while adding third parameter.
Specify datatype of third parameter to datetime.

Try it.
 
G

Guest

Try something like this:

cmd.Parameters.Add("@publication_date", DbType.DateTime).Value = DateTime.Now;
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,010
Latest member
MerrillEic

Latest Threads

Top