How do I delete rows from an access database using a script?

坚强是说给别人听的谎言 提交于 2019-12-24 11:22:40

问题


I am trying to programmatically remove rows from a Microsoft Access Database using a script (such as vbscript or whs).

It looks like there are two or more engines that can be used to connect to an mdb file which are the ADO extension Jro.JetEngine or DAO.Database DBEngine.

In addition to this, there is a column in the table called CreatedDate which contains the date that the entry was created.

I plan to use this to remove entries that are older than N days old.

How would I achieve something like this?


回答1:


You need something like this script.

connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & yourDatabase & ";"
sql = "delete from yourTable where CreateDate < " & yourDateString
set cn = createobject("ADODB.Connection")
set cmd = createobject("ADODB.Command")
cn.open connectionString
cmd.ActiveConnection = cn
cmd.CommandText = sql
cmd.execute
cn.Close

The specific connection string for your MS Access version can be had at connectionstrings.com



来源:https://stackoverflow.com/questions/5504448/how-do-i-delete-rows-from-an-access-database-using-a-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!