Problemer med ID ved delete
Hej !Jeg har problemer med at slette fra min access database.
Jeg har 2 filer
Fil 1 :
<html>
<head>
<title>Delete Entry Select</title>
</head>
<body bgcolor="white" text="black">
<%
'Dimension variables
Dim adoCon 'Holds the Database Connection Object
Dim rsGuestbook 'Holds the recordset for the records in the database
Dim strSQL 'Holds the SQL query for the database
'Create an ADO connection odject
Set adoCon = Server.CreateObject("ADODB.Connection")
'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("krcDB.mdb")
'Create an ADO recordset object
Set rsGuestbook = Server.CreateObject("ADODB.Recordset")
'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT testtabel.* FROM testtabel;"
'Open the recordset with the SQL query
rsGuestbook.Open strSQL, adoCon
'Loop through the recordset
Do While not rsGuestbook.EOF
'Write the HTML to display the current record in the recordset
Response.Write ("<br>")
Response.Write ("<a href=""delete_entry.asp?ID=" & rsGuestbook("ID_no") & """>")
Response.Write (rsGuestbook("Forfatter"))
Response.Write ("</a>")
Response.Write ("<br>")
Response.Write (rsGuestbook("Fangstmnd"))
Response.Write ("<br>")
Response.Write (rsGuestbook("Fangst"))
Response.Write ("<br>")
Response.Write (rsGuestbook("Vaegt"))
Response.Write ("<br>")
Response.Write (rsGuestbook("Sted"))
Response.Write ("<br>")
Response.Write (rsGuestbook("Metode"))
Response.Write ("<br>")
Response.Write (rsGuestbook("Beretning"))
Response.Write ("<br>")
'Move to the next record in the recordset
rsGuestbook.MoveNext
Loop
'Reset server objects
rsGuestbook.Close
Set rsGuestbook = Nothing
Set adoCon = Nothing
%>
</body>
</html>
Fil 2:
<%
'Dimension variables
Dim adoCon 'Holds the Database Connection Object
Dim rsDeleteEntry 'Holds the recordset for the record to be deleted
Dim strSQL 'Holds the SQL query for the database
Dim lngRecordNo 'Holds the record number to be deleted
'Read in the record number to be deleted
lngRecordNo = CLng(Request.QueryString("ID"))
'Create an ADO connection odject
Set adoCon = Server.CreateObject("ADODB.Connection")
'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("krcDB.mdb")
'Create an ADO recordset object
Set rsDeleteEntry = Server.CreateObject("ADODB.Recordset")
'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT testtabel.* FROM testtabel WHERE ID_no=" & lngRecordNo
'Set the lock type so that the record is locked by ADO when it is deleted
rsDeleteEntry.LockType = 3
'Open the recordset with the SQL query
rsDeleteEntry.Open strSQL, adoCon
'Delete the record from the database
rsDeleteEntry.Delete
'Reset server objects
rsDeleteEntry.Close
Set rsDeleteEntry = Nothing
Set adoCon = Nothing
'Return to the delete select page incase another record needs deleting
Response.Redirect "delete_select.asp"
%>
Den sletter fint den første man vælger med så begynder der at kommer problemer. Den skriver noget med at den række den forventede var der ikke kunne slettes da den ikke findes eller lign. Det er sikkert noget med den ID der er forkert. Kan nogle finde fejlen ??
