Solved

ASP Code problem (how to delete)?

Posted on 2004-04-04
8
299 Views
Last Modified: 2012-05-04
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.Connection")

myDSN="DSN=mydsn;uid=;pwd="

conn.open myDSN

Set rs=server.CreateObject("adodb.RecordSet")




id=Request.Form("id")

mySQL=  "Select * from name where no ='"&id&"'"

rs.cursortype=adOpenKeyset
rs.LockType=adLockOptimistic
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>
0
Comment
Question by:baburkhan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
8 Comments
 

Expert Comment

by:Bimal_M
ID: 10751493
it is deleting the record set data & not the actual data storec on the database
Try this

mySql ="Delete from name where no=' "&id" '
Con.Execute mySql
0
 

Author Comment

by:baburkhan
ID: 10751521
can you write the complete code here?
0
 

Expert Comment

by:Bimal_M
ID: 10751560
<%

dim mySQL
dim reccount

on error resume next

Set Conn=Server.CreateObject("ADODB.Connection")

myDSN="DSN=mydsn;uid=;pwd="

conn.open myDSN

Set rs=server.CreateObject("adodb.RecordSet")




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.

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:JFerraro
ID: 10753312
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("adodb.recordset")
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>
0
 

Author Comment

by:baburkhan
ID: 10775043
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.
0
 
LVL 4

Expert Comment

by:JpmSoft
ID: 10775288
Try This
...
Set CONN = Server.CreateObject("ADODB.Connection")
CONN.Execute "DELETE FROM NAME WHERE (NO=" & CStr(No) & ")"
CONN.Close
...
0
 
LVL 4

Accepted Solution

by:
JpmSoft earned 50 total points
ID: 10775298
Sorry...
The right code is this :

...
Set CONN = Server.CreateObject("ADODB.Connection")
CONN.Open "DSN=mydsn;uid=;pwd="
CONN.Execute "DELETE FROM NAME WHERE (NO=" & CStr(No) & ")"
CONN.Close
...
0
 

Expert Comment

by:JFerraro
ID: 10786894
Can you post the page that passes the ID to this one?

thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question