By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,833 Members | 2,067 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,833 IT Pros & Developers. It's quick & easy.

DateTime DataType Mismatch

P: n/a
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(strSQL, oleDbConn)

With oleDbCmd
.Parameters.AddWithValue("CID", OleDbType.VarChar).Value =
strCartID
.Parameters.AddWithValue("PID", OleDbType.VarChar).Value =
strProductID
.Parameters.AddWithValue("Qty", OleDbType.Integer).Value = iQty
.Parameters.AddWithValue("TotalAmt", OleDbType.Currency).Value =
CInt(iPrice) * CInt(iQty)
.Parameters.AddWithValue("ODate", OleDbType.DBDate).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.Date, 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.DBDate 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
Share this Question
Share on Google+
6 Replies


P: n/a
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(strSQL, oleDbConn)

With oleDbCmd.Parameters
.Add("?", OleDbType.VarChar).Value = strCartID
.Add("?", OleDbType.VarChar).Value = strProductID
.Add("?", OleDbType.Integer).Value = iQty
.Add("?", OleDbType.Currency).Value = CInt(iPrice) * CInt(iQty)
.Add("?", OleDbType.DBDate).Value = DateTime.Now
End With

oledbCmd.ExecuteNonQuery()

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**@rediffmail.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(strSQL, oleDbConn)

With oleDbCmd
.Parameters.AddWithValue("CID", OleDbType.VarChar).Value =
strCartID
.Parameters.AddWithValue("PID", OleDbType.VarChar).Value =
strProductID
.Parameters.AddWithValue("Qty", OleDbType.Integer).Value = iQty
.Parameters.AddWithValue("TotalAmt", OleDbType.Currency).Value =
CInt(iPrice) * CInt(iQty)
.Parameters.AddWithValue("ODate", OleDbType.DBDate).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.Date, 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.DBDate 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

P: n/a
On Feb 24, 10:25 pm, Milosz Skalecki [MCAD]
<mily...@DONTLIKESPAMwp.plwrote:
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(strSQL, oleDbConn)

With oleDbCmd.Parameters
.Add("?", OleDbType.VarChar).Value = strCartID
.Add("?", OleDbType.VarChar).Value = strProductID
.Add("?", OleDbType.Integer).Value = iQty
.Add("?", OleDbType.Currency).Value = CInt(iPrice) * CInt(iQty)
.Add("?", OleDbType.DBDate).Value = DateTime.Now
End With

oledbCmd.ExecuteNonQuery()

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...@rediffmail.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(strSQL, oleDbConn)
With oleDbCmd
.Parameters.AddWithValue("CID", OleDbType.VarChar).Value =
strCartID
.Parameters.AddWithValue("PID", OleDbType.VarChar).Value =
strProductID
.Parameters.AddWithValue("Qty", OleDbType.Integer).Value = iQty
.Parameters.AddWithValue("TotalAmt", OleDbType.Currency).Value =
CInt(iPrice) * CInt(iQty)
.Parameters.AddWithValue("ODate", OleDbType.DBDate).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.Date, 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.DBDate 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

P: n/a
I think both date and time are inserted, but the access shows only date part,
to make sure, run this query

select Format(OrderDate, "YYYY/DD/MM hh:mm:ss") from Cart
--
Milosz
"rn**@rediffmail.com" wrote:
On Feb 24, 10:25 pm, Milosz Skalecki [MCAD]
<mily...@DONTLIKESPAMwp.plwrote:
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(strSQL, oleDbConn)

With oleDbCmd.Parameters
.Add("?", OleDbType.VarChar).Value = strCartID
.Add("?", OleDbType.VarChar).Value = strProductID
.Add("?", OleDbType.Integer).Value = iQty
.Add("?", OleDbType.Currency).Value = CInt(iPrice) * CInt(iQty)
.Add("?", OleDbType.DBDate).Value = DateTime.Now
End With

oledbCmd.ExecuteNonQuery()

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...@rediffmail.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(strSQL, oleDbConn)
With oleDbCmd
.Parameters.AddWithValue("CID", OleDbType.VarChar).Value =
strCartID
.Parameters.AddWithValue("PID", OleDbType.VarChar).Value =
strProductID
.Parameters.AddWithValue("Qty", OleDbType.Integer).Value = iQty
.Parameters.AddWithValue("TotalAmt", OleDbType.Currency).Value =
CInt(iPrice) * CInt(iQty)
.Parameters.AddWithValue("ODate", OleDbType.DBDate).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.Date, 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.DBDate 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

P: n/a
On Feb 25, 12:16 am, Milosz Skalecki [MCAD]
<mily...@DONTLIKESPAMwp.plwrote:
I think both date and time are inserted, but the access shows only date part,
to make sure, run this query

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

"r...@rediffmail.com" wrote:
On Feb 24, 10:25 pm, Milosz Skalecki [MCAD]
<mily...@DONTLIKESPAMwp.plwrote:
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(strSQL, oleDbConn)
With oleDbCmd.Parameters
.Add("?", OleDbType.VarChar).Value = strCartID
.Add("?", OleDbType.VarChar).Value = strProductID
.Add("?", OleDbType.Integer).Value = iQty
.Add("?", OleDbType.Currency).Value = CInt(iPrice) * CInt(iQty)
.Add("?", OleDbType.DBDate).Value = DateTime.Now
End With
oledbCmd.ExecuteNonQuery()
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...@rediffmail.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(strSQL, oleDbConn)
With oleDbCmd
.Parameters.AddWithValue("CID", OleDbType.VarChar).Value =
strCartID
.Parameters.AddWithValue("PID", OleDbType.VarChar).Value =
strProductID
.Parameters.AddWithValue("Qty", OleDbType.Integer).Value = iQty
.Parameters.AddWithValue("TotalAmt", OleDbType.Currency).Value =
CInt(iPrice) * CInt(iQty)
.Parameters.AddWithValue("ODate", OleDbType.DBDate).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.Date, 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.DBDate 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

P: n/a
On Feb 25, 1:31 am, r...@rediffmail.com wrote:
On Feb 25, 12:16 am, Milosz Skalecki [MCAD]

<mily...@DONTLIKESPAMwp.plwrote:
I think both date and time are inserted, but the access shows only date part,
to make sure, run this query
select Format(OrderDate, "YYYY/DD/MM hh:mm:ss") from Cart
--
Milosz
"r...@rediffmail.com" wrote:
On Feb 24, 10:25 pm, Milosz Skalecki [MCAD]
<mily...@DONTLIKESPAMwp.plwrote:
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(strSQL, oleDbConn)
With oleDbCmd.Parameters
.Add("?", OleDbType.VarChar).Value = strCartID
.Add("?", OleDbType.VarChar).Value = strProductID
.Add("?", OleDbType.Integer).Value = iQty
.Add("?", OleDbType.Currency).Value = CInt(iPrice) * CInt(iQty)
.Add("?", OleDbType.DBDate).Value = DateTime.Now
End With
oledbCmd.ExecuteNonQuery()
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...@rediffmail.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(strSQL, oleDbConn)
With oleDbCmd
.Parameters.AddWithValue("CID", OleDbType.VarChar).Value =
strCartID
.Parameters.AddWithValue("PID", OleDbType.VarChar).Value =
strProductID
.Parameters.AddWithValue("Qty", OleDbType.Integer).Value = iQty
.Parameters.AddWithValue("TotalAmt", OleDbType.Currency).Value =
CInt(iPrice) * CInt(iQty)
.Parameters.AddWithValue("ODate", OleDbType.DBDate).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.Date, 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.DBDate 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.AddWithValue("?", DateTime.Now.ToString)

Even the obsolete Add function can be used like this:

..Parameters.Add("?", DbType.DateTime).Value = DateTime.Now.ToString

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

P: n/a
Howdy,

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

<mily...@DONTLIKESPAMwp.plwrote:
I think both date and time are inserted, but the access shows only date part,
to make sure, run this query
select Format(OrderDate, "YYYY/DD/MM hh:mm:ss") from Cart
--
Milosz
"r...@rediffmail.com" wrote:
On Feb 24, 10:25 pm, Milosz Skalecki [MCAD]
<mily...@DONTLIKESPAMwp.plwrote:
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(strSQL, oleDbConn)
With oleDbCmd.Parameters
.Add("?", OleDbType.VarChar).Value = strCartID
.Add("?", OleDbType.VarChar).Value = strProductID
.Add("?", OleDbType.Integer).Value = iQty
.Add("?", OleDbType.Currency).Value = CInt(iPrice) * CInt(iQty)
.Add("?", OleDbType.DBDate).Value = DateTime.Now
End With
oledbCmd.ExecuteNonQuery()
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...@rediffmail.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(strSQL, oleDbConn)
With oleDbCmd
.Parameters.AddWithValue("CID", OleDbType.VarChar).Value =
strCartID
.Parameters.AddWithValue("PID", OleDbType.VarChar).Value =
strProductID
.Parameters.AddWithValue("Qty", OleDbType.Integer).Value = iQty
.Parameters.AddWithValue("TotalAmt", OleDbType.Currency).Value =
CInt(iPrice) * CInt(iQty)
.Parameters.AddWithValue("ODate", OleDbType.DBDate).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.Date, 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.DBDate 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.AddWithValue("?", DateTime.Now.ToString)

Even the obsolete Add function can be used like this:

..Parameters.Add("?", DbType.DateTime).Value = DateTime.Now.ToString

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 discussion thread is closed

Replies have been disabled for this discussion.