baburkhan
asked on
ASP Code problem (how to delete)?
i want to delete the added values and wrote the following code. my database is in MSAccess.the table name is 'name' and there are only three fields in that table, 'no','lname' and 'age'. 'no' is the primary key. the page has the option to delete the added values by entering the 'no' as 'ID'. when user enter the ID and hit the delete buttong everything goes fine but the record do not delete.what should i do now? what should be the code?
<!--delete.asp-->
<!--include file="adovbs.inc"-->
<%
dim mySQL
dim reccount
on error resume next
Set Conn=Server.CreateObject(" ADODB.Conn ection")
myDSN="DSN=mydsn;uid=;pwd= "
conn.open myDSN
Set rs=server.CreateObject("ad odb.Record Set")
id=Request.Form("id")
mySQL= "Select * from name where no ='"&id&"'"
rs.cursortype=adOpenKeyset
rs.LockType=adLockOptimist ic
rs.open mySQL,conn
reccount=rs.recordcount
rs.delete
%>
<html>
<head>
<script>
function back(form) {history.back(); }
</script>
</head>
<body>
<center>
<H1> Maintenance </H1>
</center>
<br><br>
<center>
<H2>
The record has been deleted </H2>
<br><br><br>
<form>
<Input type="button" Value="Back"
onClick="back(this.form)">
</form>
</center>
</body>
</html>
<!--delete.asp-->
<!--include file="adovbs.inc"-->
<%
dim mySQL
dim reccount
on error resume next
Set Conn=Server.CreateObject("
myDSN="DSN=mydsn;uid=;pwd=
conn.open myDSN
Set rs=server.CreateObject("ad
id=Request.Form("id")
mySQL= "Select * from name where no ='"&id&"'"
rs.cursortype=adOpenKeyset
rs.LockType=adLockOptimist
rs.open mySQL,conn
reccount=rs.recordcount
rs.delete
%>
<html>
<head>
<script>
function back(form) {history.back(); }
</script>
</head>
<body>
<center>
<H1> Maintenance </H1>
</center>
<br><br>
<center>
<H2>
The record has been deleted </H2>
<br><br><br>
<form>
<Input type="button" Value="Back"
onClick="back(this.form)">
</form>
</center>
</body>
</html>
ASKER
can you write the complete code here?
<%
dim mySQL
dim reccount
on error resume next
Set Conn=Server.CreateObject(" ADODB.Conn ection")
myDSN="DSN=mydsn;uid=;pwd= "
conn.open myDSN
Set rs=server.CreateObject("ad odb.Record Set")
id=TRIM(Request.Form("id") )
mySql ="DELETE from name where no=' "&id" '
Con.Execute mySql
Con.Close
Set Rs= Nothing
Set Con=Nothing
%>
The rest will be followed by the HTML code you are using. In case you still have problem with Html code let me know.
dim mySQL
dim reccount
on error resume next
Set Conn=Server.CreateObject("
myDSN="DSN=mydsn;uid=;pwd=
conn.open myDSN
Set rs=server.CreateObject("ad
id=TRIM(Request.Form("id")
mySql ="DELETE from name where no=' "&id" '
Con.Execute mySql
Con.Close
Set Rs= Nothing
Set Con=Nothing
%>
The rest will be followed by the HTML code you are using. In case you still have problem with Html code let me know.
Although I am pretty sure all you really need to do is change the last line of your ASP code from rs.delete to "rs.delete adAffectCurrent", the following should also do the trick just in case:
Also...take a look at the back button in the HTML...
<!--delete.asp-->
<!--#include file="adovbs.inc"-->
<%
myDSN="DSN=mydsn;uid=;pwd= "
dim id, rs, sqltext
id=trim(Request.Form("id") )
ID=cInt(id)
set rs=server.createobject("ad odb.record set")
sqltext="Delete FROM name where no=" & ID
rs.open sqltext, myDSN,1,3
rs.close
set rs=nothing
%>
<html>
<head>
</head>
<body>
<center>
<H1> Maintenance </H1>
</center>
<br><br>
<center>
<H2>
The record has been successfully deleted </H2>
<br><br><br>
<Input type="button" Value="Back" onClick="history.back(-1)" >
</center>
</body>
</html>
Also...take a look at the back button in the HTML...
<!--delete.asp-->
<!--#include file="adovbs.inc"-->
<%
myDSN="DSN=mydsn;uid=;pwd=
dim id, rs, sqltext
id=trim(Request.Form("id")
ID=cInt(id)
set rs=server.createobject("ad
sqltext="Delete FROM name where no=" & ID
rs.open sqltext, myDSN,1,3
rs.close
set rs=nothing
%>
<html>
<head>
</head>
<body>
<center>
<H1> Maintenance </H1>
</center>
<br><br>
<center>
<H2>
The record has been successfully deleted </H2>
<br><br><br>
<Input type="button" Value="Back" onClick="history.back(-1)"
</center>
</body>
</html>
ASKER
i have tried but your code Jferry and Bimal but it is not working at all. what should i do now . it is updating and retrieving the records but is not deleting the values nor it gives any problem while running the scripts, except i have to change the quotes b/w &id in your code.
Try This
...
Set CONN = Server.CreateObject("ADODB .Connectio n")
CONN.Execute "DELETE FROM NAME WHERE (NO=" & CStr(No) & ")"
CONN.Close
...
...
Set CONN = Server.CreateObject("ADODB
CONN.Execute "DELETE FROM NAME WHERE (NO=" & CStr(No) & ")"
CONN.Close
...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Can you post the page that passes the ID to this one?
thanks
thanks
Try this
mySql ="Delete from name where no=' "&id" '
Con.Execute mySql