开发者

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

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 thi开发者_开发技巧s, 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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜