Deleting by Date from an MS Access Database using VB.net

  • Thread starter Thread starter RodneyB
  • Start date Start date
R

RodneyB

Guest
Im writing a VB.Net 2012 application the needs to delete records from an MS Access database based on Date criteria. Ive successfully done this when Im using the BETWEEN, but in this specific case Im trying to perform a delete on a specific date time value and it refuses to find the row. I dont get any SQL exceptions, it just doesnt delete the row.

Here is the basic SQL Statement:

DELETE FROM JobStatus WHERE JobName = MQRHOST1204 CAPACITY AND ScheduledTime = #7/29/2013 1:00:40 PM#

In the database ScheduledTime is defined as DateTime and is not a Key, not and index and not required...

Also here is the common routine I use for all my delete functions, I just pass in the SQL statement, so This code seems to be working for all the other SQL statements.

Private Function deleteFromTable(ByVal sqlStatement As String) As Boolean
-- This is a common function to delete rows from the database. It is passed a SQL Statement and deletes the requested rows.
Dim cn As New OleDbConnection(cnString)
Dim cmd As New OleDbCommand

cmd.Connection = cn
cmd.CommandType = CommandType.Text
cmd.CommandType = CommandType.Text
cmd.CommandText = sqlStatement

Try
Using cn
cn.Open()
cmd.ExecuteNonQuery() -- Actually delete the row from the database
End Using
cn.Close()
Catch ode As OleDbException
jslog.Msg(2026, MsgType.Error, ode.ToString())
Return False
Catch ex As Exception
jslog.Msg(2027, MsgType.Error, ex.ToString())
Return False
End Try

Return True
End Function
I sure would appreciate any thought someone might have on this.

Continue reading...
 
Back
Top