开发者

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

开发者 https://www.devze.com 2023-02-20 22:13 出处:网络
I am trying to programmatically remove rows from a Microsoft Access Database using a script (such as vbscript or whs).

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

精彩评论

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

关注公众号