所以我有一個名爲BrowseAllItems.asp的頁面,它顯示我所有的數據庫信息以及重定向到EditItem.asp的單獨編輯按鈕(部分顯示如下),以便編輯或刪除特定記錄的數據庫信息。編輯數據的部分工作正常,但我可以使用一些幫助刪除記錄。以下是我有:如何使用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