R
rn5a
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.
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.