Question Hellp with Datavase query and delete statement

Kasteel7

Member
Joined
Jun 7, 2009
Messages
12
Programming Experience
Beginner
Hi

Hope someone can help. :)

I have an Access database with 3 columns. (FirstName, LastName and EndDate)

I am trying to create a button that will delete all records in the database that is older than the current date. Today()

Any help would be appreciated. :)

Is this possible?

Here is what I have so far:
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=C:\Database1.mdb")

Dim cmd As OleDbCommand = New OleDbCommand("SELECT LastName, FirstName, EndDate FROM Table1 WHERE EndDate < NOT SURE WHAT TO DO HERE", con)

con.Open()
Dim myDA As OleDbDataAdapter = New OleDbDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "Table1")
Table1DataGridView.DataSource = myDataSet.Tables("Table1").DefaultView
End Sub
 
You dont need to look up the records you are going to delete, so forget *most* of what you have there. Investigate ExecuteNonQuery.

Access should be able to provide today's date without having to pass it as a parameter, so your SQL needs to be something like

VB.NET:
DELETE FROM Table1 WHERE EndDate < DATE()
 
Back
Top