Cant delete a row from a database, due to data type mismatch

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello, I am having trouble removing a row from a table of an access database. Im trying to remove a row based on a date/time that has already passed. Here is the code I have. When I try to run it I get an error.
The error states " Data type mismatch in criteria expression. "<br/>
<br/>
here is my code


<pre><div style="color:black; background-color:white <pre> <span style="color:blue Dim AMPM <span style="color:blue As <span style="color:blue String
<span style="color:blue Dim time <span style="color:blue As <span style="color:blue Date
<span style="color:blue Dim Expiretime <span style="color:blue As <span style="color:blue Date
<span style="color:blue If <span style="color:blue Date.Now.Hour - 12 < 12 <span style="color:blue Then

AMPM = <span style="color:#a31515 "PM"
<span style="color:blue Else
AMPM = <span style="color:#a31515 "AM"
<span style="color:blue End <span style="color:blue If
time = <span style="color:blue Date.Now.<span style="color:blue Date & <span style="color:#a31515 " " & <span style="color:blue Date.Now.Hour - 12 & <span style="color:#a31515 ":" & <span style="color:blue Date.Now.Minute & <span style="color:#a31515 ":" & <span style="color:blue Date.Now.Second & <span style="color:#a31515 " " & AMPM

<span style="color:blue Dim timeconnection <span style="color:blue As <span style="color:blue New OleDbConnection(<span style="color:#a31515 "Provider = Microsoft.ACE.OLEDB.12.0; Data Source = " & Application.StartupPath & <span style="color:#a31515 "ProjectDatabase.accdb")
<span style="color:blue Dim timecommand <span style="color:blue As OleDbCommand
timeconnection.Open()
timecommand = <span style="color:blue New OleDbCommand()
timecommand.Connection = timeconnection
timecommand.CommandText = <span style="color:#a31515 "SELECT ExpireTime FROM Food WHERE type = Special"
<span style="color:blue Dim timedatareader <span style="color:blue As OleDbDataReader
timedatareader = timecommand.ExecuteReader()
<span style="color:blue While timedatareader.Read

Expiretime = timedatareader.Item(0)
<span style="color:blue End <span style="color:blue While

<span style="color:blue Dim pastexp <span style="color:blue As <span style="color:blue Boolean = <span style="color:blue False
<span style="color:blue If time > Expiretime <span style="color:blue Then
pastexp = <span style="color:blue True
<span style="color:blue End <span style="color:blue If
<span style="color:blue If pastexp = <span style="color:blue True <span style="color:blue Then
<span style="color:blue Dim con <span style="color:blue As <span style="color:blue New OleDbConnection(<span style="color:#a31515 "Provider = Microsoft.ACE.OLEDB.12.0; Data Source = " & Application.StartupPath & <span style="color:#a31515 "ProjectDatabase.accdb")
<span style="color:blue Dim deleteDataSQL <span style="color:blue As <span style="color:blue String = <span style="color:#a31515 "delete * from food where type = special and ExpireTime = " & Expiretime & <span style="color:#a31515 "" <-----------
<span style="color:blue Dim command <span style="color:blue As <span style="color:blue New OleDbCommand(deleteDataSQL, con)
<span style="color:green Open the connection and execute the command
con.Open()
command.ExecuteNonQuery()
con.Close()
<span style="color:blue End <span style="color:blue If
[/code]

<br/>[/code]
I believe the problem lies where the arrow is above. The column for the ExpireDate is in a date/time format. What datatype does this need to be to be deleted from the row in my database.

<br/>
<br/>

View the full article
 
Back
Top