View Full Version : Expected End of Statement
plasterx
11-15-2005, 09:29 AM
what's wrong with this? it gave me the error:
Expected end of statment
i'm trying to delete a few records,and when i click update,it will show the updated records as in,those tat i've deleted should be already deleted.
here is my code:
.
.
.
.
.
<input type="checkbox" value="<%=rs("wholecakescode")%>" name="Delete">
<input type="submit" value="update">
Dim SQL
For i=1 to Request("Delete")
if request("Delete")(i) <> "" then
SQL = "Delete from WholeCakes where WholeCakesCode = (Request("Delete")(i))"
RS.Open SQL,Conn
End if
Next
THe error is in my SQL statement. Wha'ts wrong?????
hinch
11-15-2005, 09:42 AM
try
dArr = split(request.form("Delete"),",")
For i=0 to ubound(dArr)
if dArr(i) <> "" then
SQL = "Delete from WholeCakes where WholeCakesCode ="&dArr(i)
RS.Open SQL,Conn
End if
Next
plasterx
11-15-2005, 09:58 AM
i just tried. but i cant delete it now.it gave a different error:
invalid column name 'RC' (RC is the 1st row of my wholecakescode)
=(
hinch
11-15-2005, 10:07 AM
response.write SQL
so you can see that it is actually creating a correct sql statement
plasterx
11-15-2005, 10:10 AM
i wrote it after the 'next'.
it stil cant print out! gave me the same error ... =(((
apparently i tink the error is in that bunch of codes.
hinch
11-15-2005, 10:45 AM
<% dim conn, objRS
' Create the ADO connection component to connect the database
Set Conn = Server.CreateObject("ADODB.Connection")
' Open the database
Conn.Open = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("db.mdb")
if Request.Form("action")="delete" then
Response.Write Request.Form("DeleteMe")
dArr = split(Request.Form("DeleteMe"),",")
Set objRS = Server.CreateObject("ADODB.Recordset")
For i=0 to ubound(dArr)
objRS.Open "Delete from WholeCakes where WholeCakesCode LIKE "&dArr(i), Conn
Next
Response.Write "Items Deleted"
else
%>
<form action="" method=POST>
<%
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "select * from WholeCakes order by ID asc" , Conn
while not objRS.EOF
%>
<input type="checkbox" value="<%=objRs("wholecakescode")%>" name="DeleteMe"><%=objRs("wholecakescode")%><br />
<%
objRS.MoveNext
wend
objRS.Close
%>
<input type="submit" value="delete" id=action name=action>
</form>
<%
end if
Conn.Close
%>
glenngv
11-15-2005, 11:00 AM
Dim SQL
For i=1 to Request.Form("Delete").Count
if request.Form("Delete")(i) <> "" then
SQL = "Delete from WholeCakes where WholeCakesCode=" & Request("Delete")(i)
Conn.Execute SQL
End if
Next
plasterx
11-16-2005, 01:00 AM
thanks you two!
unfortunately the codes doesn't work.
glenngy,i tried yours and it gave me the same error. the 'invalid column name 'RC' ' error..really wonder what's it complaining about.
hinch - i tried your codes. but i got a little confused. i've got a page called 'show.asp' which basically just displays hte data from the database and has the 'delete' checkbox.
the other is update.asp where i'm supposed to write some codes(i don't know what i should be writing there)to so called activate the delete function.
where do i put your codes? do i put all into the same page - show.asp?
also the form action in the codes you gave me - should i be putting action as update.asp or show.asp? I've placed the codes you gave me (all) into update.asp.Wonder if htat's correct???
plasterx
11-16-2005, 01:59 AM
here's my show.asp
<form method="post" action="update.asp">
do while not rs.eof
<input type="checkbox" value="<%rs=("WholeCakesCode")%>" name="Delete">
rs.movenext
loop
<input type="submit" value="update">
rs.close
conn.close
</form>
here's my update.asp - i've made some changes to it:
....... (connection codes)
For i=1 to Request.Form("delete")
if request.form("delete")(i) <> "" then
sql = "delete from wholecakes whre wholecakescode = " & request("Delete")(i)
rs.open sql, conn
end if
next
response.write(Sql)
what went wrong? it gave me the error now: Type Mismatch: [string: "<the code that i attempted to delete>"]
Bullschmidt
11-16-2005, 04:15 AM
Don't know if this page really looks complete but you do have to separate between the ASP parts and the HTML parts so perhaps change this:
<form method="post" action="update.asp">
do while not rs.eof
<input type="checkbox" value="<%rs=("WholeCakesCode")%>" name="Delete">
rs.movenext
loop
<input type="submit" value="update">
rs.close
conn.close
</form>
To be more like this instead:
<form method="post" action="update.asp">
<%
do while not rs.eof
%>
<input type="checkbox" value="<%rs=("WholeCakesCode")%>" name="Delete">
<%
rs.movenext
loop
%>
<input type="submit" value="update">
<%
rs.close
conn.close
%>
</form>
glenngv
11-16-2005, 05:02 AM
here's my update.asp - i've made some changes to it:
....... (connection codes)
For i=1 to Request.Form("delete")
if request.form("delete")(i) <> "" then
sql = "delete from wholecakes whre wholecakescode = " & request("Delete")(i)
rs.open sql, conn
end if
next
response.write(Sql)
what went wrong? it gave me the error now: Type Mismatch: [string: "<the code that i attempted to delete>"]
The changes are in bold text.
For i=1 to Request.Form("Delete").Count
if request.Form("Delete")(i) <> "" then
SQL = "Delete from WholeCakes where WholeCakesCode=" & Request.Form("Delete")(i)
response.write "SQL" & i & ":" & SQL 'debug
Conn.Execute SQL
End if
Next
plasterx
11-16-2005, 06:09 AM
i used your code glenngy. but it gave me 'Invalid column name 'RC' ' .
(RC is the 1st row in my database under the field name WholeCakesCode)
plasterx
11-16-2005, 06:12 AM
i used your code glenngy. but it gave me 'Invalid column name 'RC' ' .
(RC is the 1st row in my database under the field name WholeCakesCode)
edit: i marked out the 'Conn.execute SQL and it was able to print the SQL statement correctly.
what else could be wrong ??
glenngv
11-16-2005, 08:15 AM
Is WholeCakesCode varchar or numeric? If it's a varchar then you need to enclose it in single quotes.
SQL = "Delete from WholeCakes where WholeCakesCode='" & Request.Form("Delete")(i) & "'"
plasterx
11-16-2005, 08:28 AM
It works!!!
THANKS SO MUCH !!!!!!!!!!!!
=)=)=)=)=)
=)
hinch
11-16-2005, 09:51 AM
my code was a complete page to replace your show.asp and update.asp
combined them into a single page with a post switch. does exactly what you wanted todo
plasterx
11-17-2005, 12:29 AM
=) In anyways, thanks for your help too !! Learnt quite a bit from there . =)
Cheerios!
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.