使用.NET和Access更新多个表

时间:2013-11-06 13:00:17

标签: asp.net ms-access oledbconnection oledbcommand

真的很抱歉,如果这被问过10000次,但我找不到任何相关内容。

我正在将数据库表的备份副本从开发站点发布到实际站点,我正在使用此代码执行此操作,但我还有另外10个表要复制,我确定必须有这个更容易吗?

Dim AccessConn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("../../_db/db.mdb") & "")
AccessConn.Open()
Dim AccessCommand As New System.Data.OleDb.OleDbCommand("DELETE * FROM news", AccessConn)
AccessCommand.ExecuteNonQuery()
Dim AccessCommand2 As New System.Data.OleDb.OleDbCommand("INSERT INTO news SELECT * FROM news_dev WHERE isapproved", AccessConn)
AccessCommand2.ExecuteNonQuery()
Response.Write("News Updated")
Response.Write("<br />")

Dim AccessCommand3 As New System.Data.OleDb.OleDbCommand("DELETE * FROM pages", AccessConn)
AccessCommand3.ExecuteNonQuery()
Dim AccessCommand4 As New System.Data.OleDb.OleDbCommand("INSERT INTO pages SELECT * FROM pages_dev WHERE isapproved", AccessConn)
AccessCommand4.ExecuteNonQuery()
Response.Write("Pages Updated")
Response.Write("<br />")

AccessConn.Close()

0 个答案:

没有答案