所以我有一个名为 BrowseAllItems.asp 的页面,它显示了我所有的数据库信息以及重定向到 EditItem.asp 的各个编辑按钮(部分如下所示),用于选择编辑或删除该特定记录的数据库信息。编辑数据的部分工作正常,但我可以使用一些帮助来删除记录。这是我所拥有的:
Sub DeleteRecord
ItemCode=request.form("item_code")
'Create an ADO connection object
Dim Connection
Set Connection = Server.CreateObject("ADODB.Connection")
'To open an Access database our string would look like the following:
Dim ConnectionString
ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)};" &_
"DBQ=" & Server.MapPath("\") & "\" & FolderName & "\items.mdb;DefaultDir=;UID=;PWD=;"
'Then to open the database we (optionally) set some of the properties of the Connection and call Open
Connection.ConnectionTimeout = 30
Connection.CommandTimeout = 80
Connection.Open ConnectionString
'Create an ADO recordset object
Dim rs
Set rs = Server.CreateObject("ADODB.Recordset")
'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT * FROM items WHERE ITEM_CODE='" & ItemCode & "' "
我知道这与上面的行有关——如果我用记录的实际项目代码替换“ItemCode”,则此代码有效,但我需要一种方法从所选记录中获取项目代码并将其应用到显示 ItemCode 的位置.
rs.LockType = 3
'Open the recordset with the SQL query
rs.Open strSQL, Connection
'Tell the recordset we are deleting a record
rs.Delete
rs.Close
'Reset server objects
Set rs = Nothing
Set Connection = Nothing
Response.Write "Record Deleted"
End Sub