Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Click HERE to Delete this record... 1

Status
Not open for further replies.

TonyU

Technical User
Feb 14, 2001
1,317
US
Wsup fellas....
I need someone to show me a sample on how to make a checked box delete a record from an Access database thru ASP's. Thanks.
I have a page that edits records and would like to place the check box on my edits page to delete that record if necessary. Tony
(-:
 
Since I'm not sure exactly what you need done, I will use an example of something that I do on one of my sites. I have a page that will lookup a user in the database by their first or last name or part or combination of the named. Then it will display their address, phone numbers, and email addresses...basically a quick reference for other users on the site. I make it so each person keeps track of their own info, so they can add, edit, or delete any given phone number, or email address, etc. Here's how you would do it...


---first.asp------------------------
====================================

<%
dim sql
sql = &quot;SELECT tbl_phone.phonePK, tbl_phone.userFK, tbl_phone.phoneNumber, tbl_phone.phoneType FROM tbl_phone WHERE ((tbl_phone.userFK)=&quot; & session(&quot;userPK&quot;) & &quot;);&quot;

' Where session(&quot;userPK&quot;) was set when the user signed
' into the site, and it took the primary key from the
' user list, and it requesting all the phone numbers
' with a match from the primary key to the foreign
' key on he phone list.


Set conn = server.createObject(&quot;ADODB.Connection&quot;)
DSNtemp = &quot;odbcConn&quot;
conn.Open DSNtemp
Set rs = server.createObject(&quot;ADODB.Recordset&quot;)
rs.Open sql, conn, 3, 3

response.write(&quot;<form method='post' action='second.asp'>&quot;)
Do while not rs.eof
response.write(&quot;<input type='radio' name='deleteRecord' value='&quot; & rs(&quot;phonePK&quot;) & &quot;'>Delete: &quot; & rs(&quot;phoneNumber&quot;) & &quot; &quot; & rs(&quot;phoneType&quot;) & &quot; <BR>&quot;)
rs.movenext
loop
response.write(&quot;<input type='submit' value='Submit'><input type='reset' value='Reset'>&quot;)
response.write(&quot;</form>&quot;)

conn.Close
Set conn = nothing

%>


---second.asp------------------------
=====================================

<%
dim deleteRecord, sql
deleteRecord = request.form(&quot;deleteRecord&quot;)
sql = &quot;DELETE * FROM tbl_phone WHERE ((tbl_phone.phonePK)=&quot; & deleteRecord & &quot;);&quot;

Set conn = server.createObject(&quot;ADODB.Connection&quot;)
DSNtemp = &quot;odbcConn&quot;
conn.Open DSNtemp
Set rs = server.createObject(&quot;ADODB.Recordset&quot;)
rs.Open sql, conn, 3, 3

conn.Close
Set conn = nothing

response.redirect(&quot;first.asp&quot;)

%>

Hope this helps!

-Ovatvvon
 
Just what I was looking for bud, thank you very much. Tony
(-:
 
I wonder, is there a particular reason why there is no &quot;rs.close&quot; anywhere?
When I use it, I get a msg that the operation can not happne when the object is closed.So i'm taking it off and it's ok. WHY?and what does it mean?

I wanted to delete 1 record:

set con=server.CreateObject(&quot;adodb.connection&quot;)
set rs=server.CreateObject(&quot;adodb.recordset&quot;)
con.Open &quot;dsn=...&quot;
selectQuery=&quot;DELETE from table1 where ID=4&quot;
rs.Open selectQuery, con ,3, 3
rs.close
set rs = Nothing
con.close
set con = Nothing
 
Though the record IS being deleted in both ways, but error msg just when closing rs and setting it to &quot;nothing&quot;.
Thanks in advance
 
I've run into the same problem, which is why I went to not entering the rs.close.

I honestly couldn't tell you why it does that. I would think that, that is how you should do it. To be safe and clear out the memory used by the recordset. Same as the connection.

Sorry I couldn't help you out with that knowledge!

-Ovatvvon
 
selectQuery=&quot;DELETE from table1 where ID=4&quot;
rs.Open selectQuery, con ,3, 3

your selectQuery is a command, not a query. That is why even though it does not return an error for such a statement (which I think it should), it really isn't opening anything -- no data is returned, and therefore no recordset is opened. It's simply deleting something from the database.

A more &quot;correct&quot; way to do this operation might be:

con.execute(selectQuery)

It would accomplish the same thing, and save some memory while it was at it...

hope that helps! :)
Paul Prewett
penny.gif
penny.gif
 
Thanks link9, for t he explanation. It is now clear.
I'm using the execute now for this command.
It is interesting, though, that Ovatvvon and I, and I believe many more, were using the same wrong way.
Human mind...
:)
Thanks again for your your time (Ovatvvon and link9).
 
I need something similar to TonyU's original post but will just delete checked records off of the page...but NOT physically off of the database.

&quot;JustinSaunders&quot; tried to help me out HERE--> thread333-98865 but I need someone to help me more.

I've had no luck. HELP!!!
 
Hey link9,
was gonna vote you for tipmaster, but the tipmaster link is not visible on this page.

If there is another way I can do it, please let me know cause I'll still vote it. Otherwise, just know that I'm there in state of mind.

-Ovatvvon :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top