I have a variety of ASP files managing a database and one of them should help delete entries on the database. There is a bug in the code and I would be grateful if anyone could help.
Code =
<%
DIM PathToDatabase
PathToDatabase="D:\Domains\directionsatwork.co.uk\wwwroot\cgi-bin\DATABASE.mdb"
DIM NameOfTableInDB
NameOfTableInDB="Table1"
Set DB = Server.CreateObject("ADODB.Connection")
DB.mode = adModeReadWrite
DB.Open ("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & PathToDatabase)
For Each x In Request.Form
DB.Execute("DELETE * FROM " & NameOfTableInDB & " WHERE Id=" & x)
Next
Set RS = Nothing
Set DB = Nothing
Response.redirect("dbcontrol.asp")
%>
Error message is:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'Id=value='.
<%
DIM DB
DIM RS
DIM data1st
if request.querystring="1" then
DIM PathToDatabase ' The location of our database within our server
PathToDatabase="D:\Domains\directionsatwork.co.uk\wwwroot\cgi-bin\DATABASE.mdb"
DIM NameOfTableInDB ' The name of the table in our Access database. In our case this name is "Table1"
NameOfTableInDB="Table1"
' The name of each colunm in the table is contained in the array "ColunmNameIntable".
' The sample database provided in this tutorial has up to 20 colunms
' with names "Data1" to "Data20" (and the first colunm, which is named "Id"
' As in this script we will not use all of them, only the ones we will use are included in this array
Set DB = Server.CreateObject("ADODB.Connection")
DB.Open ("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & PathToDatabase)
Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open "SELECT * FROM " & NameOfTableInDB & " Order by " & ColunmNameIntable(0) & " Desc", DB
If RS.EOF And RS.BOF Then
Response.write "There are O records."
else
RS.MoveFirst
Response.write ("<form action=dbdelete.asp method=post>")
While Not RS.EOF
Set RS = Nothing
Set DB = Nothing
Response.redirect("dbcontrol.asp")
%>
dbdelete.asp
<%
DIM PathToDatabase
PathToDatabase="D:\Domains\directionsatwork.co.uk\wwwroot\cgi-bin\DATABASE.mdb"
DIM NameOfTableInDB ' The name of the table in our Access database. In our case this name is "Table1"
NameOfTableInDB="Table1"
Set DB = Server.CreateObject("ADODB.Connection")
DB.mode = adModeReadWrite
DB.Open ("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & PathToDatabase)
For Each x In Request.Form
DB.Execute("DELETE * FROM " & NameOfTableInDB & " WHERE Id=" & x)
Next
Set RS = Nothing
Set DB = Nothing
Response.redirect("dbcontrol.asp")
%>
Dim PathToDatabase
PathToDatabase="D:\Domains\directionsatwork.co.uk\wwwroot\cgi-bin\DATABASE.mdb"
Dim NameOfTableInDB ' The name of the table in our Access database. In our case this name is "Table1"
NameOfTableInDB="Table1"
Dim ar
Dim i
ar = Split(Request.Form("id"), ",")
Set DB = Server.CreateObject("ADODB.Connection")
DB.mode = adModeReadWrite
DB.Open ("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & PathToDatabase)
For i = 0 To ubound(ar)
DB.Execute("DELETE FROM " & NameOfTableInDB & " WHERE Id=" & clng(ar(i)))
Next
Set RS = Nothing
Set DB = Nothing
Response.redirect("dbcontrol.asp")
how many check boxs checked?
in dbcontrol.asp, if u view source, what is in the html for the value of the checkboxes?
try changing db.execute("Delete...
to
Response.Write "Delete...
and comment out the redirect. this will show the query u r trying to execute. what does it show?
Bookmarks