473,756 Members | 3,973 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DateTime DataType Mismatch

I am inserting records in a MS-Access database table. The data type of
one of the columns named *OrderDate* in the DB table is Date/Time.
This is the SQL query I am using to insert the records in the Access
DB table:

=============== =============== =
strSQL = "INSERT INTO Cart (CartID, ProductID, Quantity, Total,
OrderDate) VALUES (CID, PID, Qty, TotalAmt, ODate)"

oleDbCmd = New OleDbCommand(st rSQL, oleDbConn)

With oleDbCmd
.Parameters.Add WithValue("CID" , OleDbType.VarCh ar).Value =
strCartID
.Parameters.Add WithValue("PID" , OleDbType.VarCh ar).Value =
strProductID
.Parameters.Add WithValue("Qty" , OleDbType.Integ er).Value = iQty
.Parameters.Add WithValue("Tota lAmt", OleDbType.Curre ncy).Value =
CInt(iPrice) * CInt(iQty)
.Parameters.Add WithValue("ODat e", OleDbType.DBDat e).Value =
DateTime.Now
End With
=============== =============== =

I want the *OrderDate* column in the Access DB table to have both the
date & the time. The problem is there is no support for a combination
of both date & time in OLEDB. The datatypes supported allow EITHER
date OR time but not both. Hence the above code generates the
following error:

Data type mismatch in criteria expression.

since DateTime.Now gets both the date & the time. If I replace
DateTime.Now in the above code with DateTime.Now.Da te, then the above
SQL query executes successfully & inserts records in the DB table but
it adds only the date part in the *OrderDate* column & omits the time
part whereas I want the records under the *OrderDate* column in the DB
table to have both the date as well as the time. Changing the data
type of the last parameter in the above code from OleDbType.DBDat e to
OleDbType.Date also doesn't make any difference. The error still
persists.

How do I resolve this issue?

One workaround is to add a new Date/Time data type column in the DB
table & pass another parameter from the ASP.NET code to insert only
the time part but that's a last option if there isn't any other
workaround.

Feb 24 '07 #1
6 3394
Howdy,

I think dbdate is ok. First, you've missedused AddWithValue function which
expects parameter name and it's value (but you are passing DbType enumeration
as value).Second i suspect there is a problem with insert query at
'values(blabla) '. I might be wrong but this form of passing parameters is not
supported by jet provider (ms access) I think this should go like following:

strSQL = "INSERT INTO Cart (CartID, ProductID, Quantity, Total,
OrderDate) VALUES (?, ?, ?, ?, ?)"

oleDbCmd = New OleDbCommand(st rSQL, oleDbConn)

With oleDbCmd.Parame ters
.Add("?", OleDbType.VarCh ar).Value = strCartID
.Add("?", OleDbType.VarCh ar).Value = strProductID
.Add("?", OleDbType.Integ er).Value = iQty
.Add("?", OleDbType.Curre ncy).Value = CInt(iPrice) * CInt(iQty)
.Add("?", OleDbType.DBDat e).Value = DateTime.Now
End With

oledbCmd.Execut eNonQuery()

Aboive snippet should work. By the way, I'm not sure about the logic you
calculate total price as curency:
CInt(iPrice) * CInt(iQty)
which will always return integer.

Hope this helps
--
Milosz
"rn**@rediffmai l.com" wrote:
I am inserting records in a MS-Access database table. The data type of
one of the columns named *OrderDate* in the DB table is Date/Time.
This is the SQL query I am using to insert the records in the Access
DB table:

=============== =============== =
strSQL = "INSERT INTO Cart (CartID, ProductID, Quantity, Total,
OrderDate) VALUES (CID, PID, Qty, TotalAmt, ODate)"

oleDbCmd = New OleDbCommand(st rSQL, oleDbConn)

With oleDbCmd
.Parameters.Add WithValue("CID" , OleDbType.VarCh ar).Value =
strCartID
.Parameters.Add WithValue("PID" , OleDbType.VarCh ar).Value =
strProductID
.Parameters.Add WithValue("Qty" , OleDbType.Integ er).Value = iQty
.Parameters.Add WithValue("Tota lAmt", OleDbType.Curre ncy).Value =
CInt(iPrice) * CInt(iQty)
.Parameters.Add WithValue("ODat e", OleDbType.DBDat e).Value =
DateTime.Now
End With
=============== =============== =

I want the *OrderDate* column in the Access DB table to have both the
date & the time. The problem is there is no support for a combination
of both date & time in OLEDB. The datatypes supported allow EITHER
date OR time but not both. Hence the above code generates the
following error:

Data type mismatch in criteria expression.

since DateTime.Now gets both the date & the time. If I replace
DateTime.Now in the above code with DateTime.Now.Da te, then the above
SQL query executes successfully & inserts records in the DB table but
it adds only the date part in the *OrderDate* column & omits the time
part whereas I want the records under the *OrderDate* column in the DB
table to have both the date as well as the time. Changing the data
type of the last parameter in the above code from OleDbType.DBDat e to
OleDbType.Date also doesn't make any difference. The error still
persists.

How do I resolve this issue?

One workaround is to add a new Date/Time data type column in the DB
table & pass another parameter from the ASP.NET code to insert only
the time part but that's a last option if there isn't any other
workaround.

Feb 24 '07 #2
On Feb 24, 10:25 pm, Milosz Skalecki [MCAD]
<mily...@DONTLI KESPAMwp.plwrot e:
Howdy,

I think dbdate is ok. First, you've missedused AddWithValue function which
expects parameter name and it's value (but you are passing DbType enumeration
as value).Second i suspect there is a problem with insert query at
'values(blabla) '. I might be wrong but this form of passing parameters is not
supported by jet provider (ms access) I think this should go like following:

strSQL = "INSERT INTO Cart (CartID, ProductID, Quantity, Total,
OrderDate) VALUES (?, ?, ?, ?, ?)"

oleDbCmd = New OleDbCommand(st rSQL, oleDbConn)

With oleDbCmd.Parame ters
.Add("?", OleDbType.VarCh ar).Value = strCartID
.Add("?", OleDbType.VarCh ar).Value = strProductID
.Add("?", OleDbType.Integ er).Value = iQty
.Add("?", OleDbType.Curre ncy).Value = CInt(iPrice) * CInt(iQty)
.Add("?", OleDbType.DBDat e).Value = DateTime.Now
End With

oledbCmd.Execut eNonQuery()

Aboive snippet should work. By the way, I'm not sure about the logic you
calculate total price as curency:
CInt(iPrice) * CInt(iQty)
which will always return integer.

Hope this helps
--
Milosz

"r...@rediffmai l.com" wrote:
I am inserting records in a MS-Access database table. The data type of
one of the columns named *OrderDate* in the DB table is Date/Time.
This is the SQL query I am using to insert the records in the Access
DB table:
=============== =============== =
strSQL = "INSERT INTO Cart (CartID, ProductID, Quantity, Total,
OrderDate) VALUES (CID, PID, Qty, TotalAmt, ODate)"
oleDbCmd = New OleDbCommand(st rSQL, oleDbConn)
With oleDbCmd
.Parameters.Add WithValue("CID" , OleDbType.VarCh ar).Value =
strCartID
.Parameters.Add WithValue("PID" , OleDbType.VarCh ar).Value =
strProductID
.Parameters.Add WithValue("Qty" , OleDbType.Integ er).Value = iQty
.Parameters.Add WithValue("Tota lAmt", OleDbType.Curre ncy).Value =
CInt(iPrice) * CInt(iQty)
.Parameters.Add WithValue("ODat e", OleDbType.DBDat e).Value =
DateTime.Now
End With
=============== =============== =
I want the *OrderDate* column in the Access DB table to have both the
date & the time. The problem is there is no support for a combination
of both date & time in OLEDB. The datatypes supported allow EITHER
date OR time but not both. Hence the above code generates the
following error:
Data type mismatch in criteria expression.
since DateTime.Now gets both the date & the time. If I replace
DateTime.Now in the above code with DateTime.Now.Da te, then the above
SQL query executes successfully & inserts records in the DB table but
it adds only the date part in the *OrderDate* column & omits the time
part whereas I want the records under the *OrderDate* column in the DB
table to have both the date as well as the time. Changing the data
type of the last parameter in the above code from OleDbType.DBDat e to
OleDbType.Date also doesn't make any difference. The error still
persists.
How do I resolve this issue?
One workaround is to add a new Date/Time data type column in the DB
table & pass another parameter from the ASP.NET code to insert only
the time part but that's a last option if there isn't any other
workaround.- Hide quoted text -

- Show quoted text -
Milosz, if I insert records as you have suggested (using '?'), then it
doesn't generate any error & also inserts the record in the DB table
successfully but still only the date part gets inserted & not the time
part in the *OrderDate* column. For e.g. if the current date & time
now is

24/02/2007 6:56:34 PM

then only

24/02/2007 gets inserted in the *OrderDate* column; the time part gets
omitted.

Any other suggestions?

Feb 24 '07 #3
I think both date and time are inserted, but the access shows only date part,
to make sure, run this query

select Format(OrderDat e, "YYYY/DD/MM hh:mm:ss") from Cart
--
Milosz
"rn**@rediffmai l.com" wrote:
On Feb 24, 10:25 pm, Milosz Skalecki [MCAD]
<mily...@DONTLI KESPAMwp.plwrot e:
Howdy,

I think dbdate is ok. First, you've missedused AddWithValue function which
expects parameter name and it's value (but you are passing DbType enumeration
as value).Second i suspect there is a problem with insert query at
'values(blabla) '. I might be wrong but this form of passing parameters is not
supported by jet provider (ms access) I think this should go like following:

strSQL = "INSERT INTO Cart (CartID, ProductID, Quantity, Total,
OrderDate) VALUES (?, ?, ?, ?, ?)"

oleDbCmd = New OleDbCommand(st rSQL, oleDbConn)

With oleDbCmd.Parame ters
.Add("?", OleDbType.VarCh ar).Value = strCartID
.Add("?", OleDbType.VarCh ar).Value = strProductID
.Add("?", OleDbType.Integ er).Value = iQty
.Add("?", OleDbType.Curre ncy).Value = CInt(iPrice) * CInt(iQty)
.Add("?", OleDbType.DBDat e).Value = DateTime.Now
End With

oledbCmd.Execut eNonQuery()

Aboive snippet should work. By the way, I'm not sure about the logic you
calculate total price as curency:
CInt(iPrice) * CInt(iQty)
which will always return integer.

Hope this helps
--
Milosz

"r...@rediffmai l.com" wrote:
I am inserting records in a MS-Access database table. The data type of
one of the columns named *OrderDate* in the DB table is Date/Time.
This is the SQL query I am using to insert the records in the Access
DB table:
=============== =============== =
strSQL = "INSERT INTO Cart (CartID, ProductID, Quantity, Total,
OrderDate) VALUES (CID, PID, Qty, TotalAmt, ODate)"
oleDbCmd = New OleDbCommand(st rSQL, oleDbConn)
With oleDbCmd
.Parameters.Add WithValue("CID" , OleDbType.VarCh ar).Value =
strCartID
.Parameters.Add WithValue("PID" , OleDbType.VarCh ar).Value =
strProductID
.Parameters.Add WithValue("Qty" , OleDbType.Integ er).Value = iQty
.Parameters.Add WithValue("Tota lAmt", OleDbType.Curre ncy).Value =
CInt(iPrice) * CInt(iQty)
.Parameters.Add WithValue("ODat e", OleDbType.DBDat e).Value =
DateTime.Now
End With
=============== =============== =
I want the *OrderDate* column in the Access DB table to have both the
date & the time. The problem is there is no support for a combination
of both date & time in OLEDB. The datatypes supported allow EITHER
date OR time but not both. Hence the above code generates the
following error:
Data type mismatch in criteria expression.
since DateTime.Now gets both the date & the time. If I replace
DateTime.Now in the above code with DateTime.Now.Da te, then the above
SQL query executes successfully & inserts records in the DB table but
it adds only the date part in the *OrderDate* column & omits the time
part whereas I want the records under the *OrderDate* column in the DB
table to have both the date as well as the time. Changing the data
type of the last parameter in the above code from OleDbType.DBDat e to
OleDbType.Date also doesn't make any difference. The error still
persists.
How do I resolve this issue?
One workaround is to add a new Date/Time data type column in the DB
table & pass another parameter from the ASP.NET code to insert only
the time part but that's a last option if there isn't any other
workaround.- Hide quoted text -
- Show quoted text -

Milosz, if I insert records as you have suggested (using '?'), then it
doesn't generate any error & also inserts the record in the DB table
successfully but still only the date part gets inserted & not the time
part in the *OrderDate* column. For e.g. if the current date & time
now is

24/02/2007 6:56:34 PM

then only

24/02/2007 gets inserted in the *OrderDate* column; the time part gets
omitted.

Any other suggestions?

Feb 24 '07 #4
On Feb 25, 12:16 am, Milosz Skalecki [MCAD]
<mily...@DONTLI KESPAMwp.plwrot e:
I think both date and time are inserted, but the access shows only date part,
to make sure, run this query

select Format(OrderDat e, "YYYY/DD/MM hh:mm:ss") from Cart
--
Milosz

"r...@rediffmai l.com" wrote:
On Feb 24, 10:25 pm, Milosz Skalecki [MCAD]
<mily...@DONTLI KESPAMwp.plwrot e:
Howdy,
I think dbdate is ok. First, you've missedused AddWithValue function which
expects parameter name and it's value (but you are passing DbType enumeration
as value).Second i suspect there is a problem with insert query at
'values(blabla) '. I might be wrong but this form of passing parameters is not
supported by jet provider (ms access) I think this should go like following:
strSQL = "INSERT INTO Cart (CartID, ProductID, Quantity, Total,
OrderDate) VALUES (?, ?, ?, ?, ?)"
oleDbCmd = New OleDbCommand(st rSQL, oleDbConn)
With oleDbCmd.Parame ters
.Add("?", OleDbType.VarCh ar).Value = strCartID
.Add("?", OleDbType.VarCh ar).Value = strProductID
.Add("?", OleDbType.Integ er).Value = iQty
.Add("?", OleDbType.Curre ncy).Value = CInt(iPrice) * CInt(iQty)
.Add("?", OleDbType.DBDat e).Value = DateTime.Now
End With
oledbCmd.Execut eNonQuery()
Aboive snippet should work. By the way, I'm not sure about the logic you
calculate total price as curency:
CInt(iPrice) * CInt(iQty)
which will always return integer.
Hope this helps
--
Milosz
"r...@rediffmai l.com" wrote:
I am inserting records in a MS-Access database table. The data type of
one of the columns named *OrderDate* in the DB table is Date/Time.
This is the SQL query I am using to insert the records in the Access
DB table:
=============== =============== =
strSQL = "INSERT INTO Cart (CartID, ProductID, Quantity, Total,
OrderDate) VALUES (CID, PID, Qty, TotalAmt, ODate)"
oleDbCmd = New OleDbCommand(st rSQL, oleDbConn)
With oleDbCmd
.Parameters.Add WithValue("CID" , OleDbType.VarCh ar).Value =
strCartID
.Parameters.Add WithValue("PID" , OleDbType.VarCh ar).Value =
strProductID
.Parameters.Add WithValue("Qty" , OleDbType.Integ er).Value = iQty
.Parameters.Add WithValue("Tota lAmt", OleDbType.Curre ncy).Value =
CInt(iPrice) * CInt(iQty)
.Parameters.Add WithValue("ODat e", OleDbType.DBDat e).Value =
DateTime.Now
End With
=============== =============== =
I want the *OrderDate* column in the Access DB table to have both the
date & the time. The problem is there is no support for a combination
of both date & time in OLEDB. The datatypes supported allow EITHER
date OR time but not both. Hence the above code generates the
following error:
Data type mismatch in criteria expression.
since DateTime.Now gets both the date & the time. If I replace
DateTime.Now in the above code with DateTime.Now.Da te, then the above
SQL query executes successfully & inserts records in the DB table but
it adds only the date part in the *OrderDate* column & omits the time
part whereas I want the records under the *OrderDate* column in the DB
table to have both the date as well as the time. Changing the data
type of the last parameter in the above code from OleDbType.DBDat e to
OleDbType.Date also doesn't make any difference. The error still
persists.
How do I resolve this issue?
One workaround is to add a new Date/Time data type column in the DB
table & pass another parameter from the ASP.NET code to insert only
the time part but that's a last option if there isn't any other
workaround.- Hide quoted text -
- Show quoted text -
Milosz, if I insert records as you have suggested (using '?'), then it
doesn't generate any error & also inserts the record in the DB table
successfully but still only the date part gets inserted & not the time
part in the *OrderDate* column. For e.g. if the current date & time
now is
24/02/2007 6:56:34 PM
then only
24/02/2007 gets inserted in the *OrderDate* column; the time part gets
omitted.
Any other suggestions?- Hide quoted text -

- Show quoted text -
When I executed your query, Milosz, the record under the *OrderDate*
column showed the date part but it showed the time part as 00:00:00
like for e.g.

24/02/2007 00:00:00

What next??

Feb 24 '07 #5
On Feb 25, 1:31 am, r...@rediffmail .com wrote:
On Feb 25, 12:16 am, Milosz Skalecki [MCAD]

<mily...@DONTLI KESPAMwp.plwrot e:
I think both date and time are inserted, but the access shows only date part,
to make sure, run this query
select Format(OrderDat e, "YYYY/DD/MM hh:mm:ss") from Cart
--
Milosz
"r...@rediffmai l.com" wrote:
On Feb 24, 10:25 pm, Milosz Skalecki [MCAD]
<mily...@DONTLI KESPAMwp.plwrot e:
Howdy,
I think dbdate is ok. First, you've missedused AddWithValue function which
expects parameter name and it's value (but you are passing DbType enumeration
as value).Second i suspect there is a problem with insert query at
'values(blabla) '. I might be wrong but this form of passing parameters is not
supported by jet provider (ms access) I think this should go like following:
strSQL = "INSERT INTO Cart (CartID, ProductID, Quantity, Total,
OrderDate) VALUES (?, ?, ?, ?, ?)"
oleDbCmd = New OleDbCommand(st rSQL, oleDbConn)
With oleDbCmd.Parame ters
.Add("?", OleDbType.VarCh ar).Value = strCartID
.Add("?", OleDbType.VarCh ar).Value = strProductID
.Add("?", OleDbType.Integ er).Value = iQty
.Add("?", OleDbType.Curre ncy).Value = CInt(iPrice) * CInt(iQty)
.Add("?", OleDbType.DBDat e).Value = DateTime.Now
End With
oledbCmd.Execut eNonQuery()
Aboive snippet should work. By the way, I'm not sure about the logic you
calculate total price as curency:
CInt(iPrice) * CInt(iQty)
which will always return integer.
Hope this helps
--
Milosz
"r...@rediffmai l.com" wrote:
I am inserting records in a MS-Access database table. The data type of
one of the columns named *OrderDate* in the DB table is Date/Time.
This is the SQL query I am using to insert the records in the Access
DB table:
=============== =============== =
strSQL = "INSERT INTO Cart (CartID, ProductID, Quantity, Total,
OrderDate) VALUES (CID, PID, Qty, TotalAmt, ODate)"
oleDbCmd = New OleDbCommand(st rSQL, oleDbConn)
With oleDbCmd
.Parameters.Add WithValue("CID" , OleDbType.VarCh ar).Value =
strCartID
.Parameters.Add WithValue("PID" , OleDbType.VarCh ar).Value =
strProductID
.Parameters.Add WithValue("Qty" , OleDbType.Integ er).Value = iQty
.Parameters.Add WithValue("Tota lAmt", OleDbType.Curre ncy).Value =
CInt(iPrice) * CInt(iQty)
.Parameters.Add WithValue("ODat e", OleDbType.DBDat e).Value =
DateTime.Now
End With
=============== =============== =
I want the *OrderDate* column in the Access DB table to have both the
date & the time. The problem is there is no support for a combination
of both date & time in OLEDB. The datatypes supported allow EITHER
date OR time but not both. Hence the above code generates the
following error:
Data type mismatch in criteria expression.
since DateTime.Now gets both the date & the time. If I replace
DateTime.Now in the above code with DateTime.Now.Da te, then the above
SQL query executes successfully & inserts records in the DB table but
it adds only the date part in the *OrderDate* column & omits the time
part whereas I want the records under the *OrderDate* column in the DB
table to have both the date as well as the time. Changing the data
type of the last parameter in the above code from OleDbType.DBDat e to
OleDbType.Date also doesn't make any difference. The error still
persists.
How do I resolve this issue?
One workaround is to add a new Date/Time data type column in the DB
table & pass another parameter from the ASP.NET code to insert only
the time part but that's a last option if there isn't any other
workaround.- Hide quoted text -
- Show quoted text -
Milosz, if I insert records as you have suggested (using '?'), then it
doesn't generate any error & also inserts the record in the DB table
successfully but still only the date part gets inserted & not the time
part in the *OrderDate* column. For e.g. if the current date & time
now is
24/02/2007 6:56:34 PM
then only
24/02/2007 gets inserted in the *OrderDate* column; the time part gets
omitted.
Any other suggestions?- Hide quoted text -
- Show quoted text -

When I executed your query, Milosz, the record under the *OrderDate*
column showed the date part but it showed the time part as 00:00:00
like for e.g.

24/02/2007 00:00:00

What next??- Hide quoted text -

- Show quoted text -
Milosz, the following inserts both date & time in the Access DB
column:

..Parameters.Ad dWithValue("?", DateTime.Now.To String)

Even the obsolete Add function can be used like this:

..Parameters.Ad d("?", DbType.DateTime ).Value = DateTime.Now.To String

Strangely, in both cases, omitting the ToString function generates the

Data type mismatch in criteria expression.

error though the column in the Access DB table is of type Date/Time!

Any idea why?

Feb 25 '07 #6
Howdy,

Maybe something else generates mentioned mismatch exception. Could you give
me all the columns names with type please?
--
Milosz
"rn**@rediffmai l.com" wrote:
On Feb 25, 1:31 am, r...@rediffmail .com wrote:
On Feb 25, 12:16 am, Milosz Skalecki [MCAD]

<mily...@DONTLI KESPAMwp.plwrot e:
I think both date and time are inserted, but the access shows only date part,
to make sure, run this query
select Format(OrderDat e, "YYYY/DD/MM hh:mm:ss") from Cart
--
Milosz
"r...@rediffmai l.com" wrote:
On Feb 24, 10:25 pm, Milosz Skalecki [MCAD]
<mily...@DONTLI KESPAMwp.plwrot e:
Howdy,
I think dbdate is ok. First, you've missedused AddWithValue function which
expects parameter name and it's value (but you are passing DbType enumeration
as value).Second i suspect there is a problem with insert query at
'values(blabla) '. I might be wrong but this form of passing parameters is not
supported by jet provider (ms access) I think this should go like following:
strSQL = "INSERT INTO Cart (CartID, ProductID, Quantity, Total,
OrderDate) VALUES (?, ?, ?, ?, ?)"
oleDbCmd = New OleDbCommand(st rSQL, oleDbConn)
With oleDbCmd.Parame ters
.Add("?", OleDbType.VarCh ar).Value = strCartID
.Add("?", OleDbType.VarCh ar).Value = strProductID
.Add("?", OleDbType.Integ er).Value = iQty
.Add("?", OleDbType.Curre ncy).Value = CInt(iPrice) * CInt(iQty)
.Add("?", OleDbType.DBDat e).Value = DateTime.Now
End With
oledbCmd.Execut eNonQuery()
Aboive snippet should work. By the way, I'm not sure about the logic you
calculate total price as curency:
CInt(iPrice) * CInt(iQty)
which will always return integer.
Hope this helps
--
Milosz
"r...@rediffmai l.com" wrote:
I am inserting records in a MS-Access database table. The data type of
one of the columns named *OrderDate* in the DB table is Date/Time.
This is the SQL query I am using to insert the records in the Access
DB table:
=============== =============== =
strSQL = "INSERT INTO Cart (CartID, ProductID, Quantity, Total,
OrderDate) VALUES (CID, PID, Qty, TotalAmt, ODate)"
oleDbCmd = New OleDbCommand(st rSQL, oleDbConn)
With oleDbCmd
.Parameters.Add WithValue("CID" , OleDbType.VarCh ar).Value =
strCartID
.Parameters.Add WithValue("PID" , OleDbType.VarCh ar).Value =
strProductID
.Parameters.Add WithValue("Qty" , OleDbType.Integ er).Value = iQty
.Parameters.Add WithValue("Tota lAmt", OleDbType.Curre ncy).Value =
CInt(iPrice) * CInt(iQty)
.Parameters.Add WithValue("ODat e", OleDbType.DBDat e).Value =
DateTime.Now
End With
=============== =============== =
I want the *OrderDate* column in the Access DB table to have both the
date & the time. The problem is there is no support for a combination
of both date & time in OLEDB. The datatypes supported allow EITHER
date OR time but not both. Hence the above code generates the
following error:
Data type mismatch in criteria expression.
since DateTime.Now gets both the date & the time. If I replace
DateTime.Now in the above code with DateTime.Now.Da te, then the above
SQL query executes successfully & inserts records in the DB table but
it adds only the date part in the *OrderDate* column & omits the time
part whereas I want the records under the *OrderDate* column in the DB
table to have both the date as well as the time. Changing the data
type of the last parameter in the above code from OleDbType.DBDat e to
OleDbType.Date also doesn't make any difference. The error still
persists.
How do I resolve this issue?
One workaround is to add a new Date/Time data type column in the DB
table & pass another parameter from the ASP.NET code to insert only
the time part but that's a last option if there isn't any other
workaround.- Hide quoted text -
- Show quoted text -
Milosz, if I insert records as you have suggested (using '?'), then it
doesn't generate any error & also inserts the record in the DB table
successfully but still only the date part gets inserted & not the time
part in the *OrderDate* column. For e.g. if the current date & time
now is
24/02/2007 6:56:34 PM
then only
24/02/2007 gets inserted in the *OrderDate* column; the time part gets
omitted.
Any other suggestions?- Hide quoted text -
- Show quoted text -
When I executed your query, Milosz, the record under the *OrderDate*
column showed the date part but it showed the time part as 00:00:00
like for e.g.

24/02/2007 00:00:00

What next??- Hide quoted text -

- Show quoted text -

Milosz, the following inserts both date & time in the Access DB
column:

..Parameters.Ad dWithValue("?", DateTime.Now.To String)

Even the obsolete Add function can be used like this:

..Parameters.Ad d("?", DbType.DateTime ).Value = DateTime.Now.To String

Strangely, in both cases, omitting the ToString function generates the

Data type mismatch in criteria expression.

error though the column in the Access DB table is of type Date/Time!

Any idea why?

Feb 25 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2927
by: Stephen Briley | last post by:
For some reason, my posts are scrubbed as attachments. Lets hope that sending from the yahoo account works. I'm new to Python and I'm trying to do some database work with MS Access, but I can't seem to get around a "datatype mismatch error". Here's an example table that I'm working with... ID name dept 1 steve acct
2
2124
by: Steve Briley | last post by:
I'm new to Python and I'm trying to do some database work with MS Access, but I can't seem to get around a "datatype mismatch error".&nbsp; Here's an example table that I'm working with... &nbsp; ID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name&nbsp;&nbsp;&nbsp; dept 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; steve&nbsp;&nbsp; acct
1
2486
by: Ken | last post by:
I wrote a function to use in queries that takes a date and adds or subtracts a certain length time and then returns the new value. There are times when my function needs to return Null values. Function DateCalc (blah...) As Variant Do Stuff... If Not IsNull(varNewDate) Then DateCalc = varNewDate End If End Function
9
4928
by: Phil B | last post by:
I am having a problem with a datetime from a web services provider The provider is sending the following SOAP response <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="urn:JadeWebServices/WebServiceProvider/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
0
1654
by: vijayalakshmi.venkataraman | last post by:
Hello, I have a .NET client that accesses a Java webservice. Let me first say that the client stub I got generated from the wsdl was incomplete and had to make changes to it manually to make it work to an extent. I generated a java client stub for the java web service and have been modifying my .NET client stub using the java client stub as a reference and things seemed to work fine until I got the following error. In my client...
11
21917
by: Matt F | last post by:
I'm trying to do something that seems like it should be pretty simple, but haven't found a solution. I am trying to add a datacolumn to a datatable that adds or subtracts a number of days based on another datetime column in the table. See sample below. How do I do this? Any help would be greatly appreciated. Thanks Private Sub CreateDataTable() dt = New DataTable
2
1559
by: chirag1989 | last post by:
I m havin an error of datatype mismatch actual here i m askin user to input the code in text box and then searchin the record havin that code in database the problem is the code field Bnum is of number datatype so its showin me this error Microsoft JET Database Engine (0x80040E07) Data type mismatch in criteria expression. /library/12updbook1.asp, line 128
9
2225
by: rscheinberg | last post by:
I am working in Access 2007 attempting to grab 2 characters from a text field named ProjectNumber. After determining what 2 digits to add in front to make it a year, I need to do that. I have done that in the code below to create a value for "intPN". I then need that value to become a number so that I can compare it to a range of years (1983-1987). The code below returns the 4 character year as intended. But I get a Datatype mismatch error...
14
1889
by: rscheinberg | last post by:
I am working in Access 2007 attempting to grab 2 characters from a text field named ProjectNumber. After determining what 2 digits to add in front to make it a year, I need to do that. I have done that in the code below to create a value for "intPN". I then need that value to become a number so that I can compare it to a range of years (1983-1987). The code below returns the 4 character year as intended. But I get a Datatype mismatch in criteria...
1
9838
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9708
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8709
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7242
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5140
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3354
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2665
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.