Home All Groups Group Topic Archive Search About

Strange Date/Time problem

Author
30 Jun 2005 11:18 PM
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

Author
1 Jul 2005 12:39 AM
Alejandro Mesa
Shapper,

I think you are using the wrong oledbparameter overload constructor. Try:

dbCommand.Parameters.Add("@publication_date", OleDbType.DBTimeStamp).Value =
DateTime.Now


AMB


Show quote
"Shapper" wrote:

> 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
>
>

AddThis Social Bookmark Button