If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > delete multiple records using checkbox

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-12-06, 10:43
irisclaire irisclaire is offline
Registered User
 
Join Date: Jan 2006
Posts: 10
delete error...

hi guys....
whats wrong with this code... every time i'll use this it deletes the whole content of the database, instead of deleting only the record i choose.

<%
Dim msgid
msgid = Request.Form("msgid")

Dim Conn
Dim Rs
Dim sql
Set Conn = Server.CreateObject("ADODB.Connection")
Set Rs = Server.CreateObject("ADODB.Recordset")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("blog.mdb") & ";"
sql= "Delete FROM messagetable WHERE 'msgid='"& msgid &""
Rs.Open sql, Conn
Conn.Close
Set Conn = Nothing
Response.redirect "adminshowmain.asp?sortby=msgid"
%>

Can anybody enlighten me with this problem??

thanks

Last edited by irisclaire; 01-14-06 at 09:11.
Reply With Quote
  #2 (permalink)  
Old 01-12-06, 12:02
fredservillon fredservillon is offline
Registered User
 
Join Date: Oct 2005
Posts: 178
Quote:
Originally Posted by irisclaire
Hi guys! I'm just new in ASP and I'm creating a simple message board. I just want to know the codes on how to delete multiple records using a checkbox.

I have an access database and a table named tblMessage, it has fields namely: MsgID,Title,Body,and Date and another table named tblUser with fields UserID,Uname. When I display the asp page it looks like this....

************************************************** *********
Date Subject Posted by
(the date) (title of the message) (user who posted it)
************************************************** *********

What I want to do now here are checkboxes beside the date, so when these checkboxes are checked, then the delete button is clicked, it would delete the multiple records checked. I don't know where to start....

Can anybody enlighten me with this problem??

Thanks!!!!

I'll start you with something, you can finish the next process to delete the records from your database.
This code will have option to check and uncheck the checkboxes all at once or just one as you prefer.

Create a checkbox input type and call it MyCheckBox for example..

Code:
<SCRIPT LANGUAGE="Javascript">

<!--
function SetChecked(val) {
dml=document.MessageForm;
len= dml.elements.length;
var i=0;
for( i=0 ; i<len ; i++) {
if (dml.elements[i].name=='MyCheckBox') {
dml.elements[i].checked=val;

}
}
}

</Script>
<Head>

</Head>

<body >

<form method="Post" name = "MessageForm"  action="GoDeletethem.asp">

' this will be above and/or bottom of your table or message listing. 

<table><tr><td><a href="javascript:SetChecked(1)"><font face="Verdana" size="1" color="Blue">Check&nbsp;All</font></a>
</td><td>&nbsp;&nbsp;&nbsp;</td><td><a href="javascript:SetChecked(0)"><font face="Verdana" size="1" color="Blue">UnCheck&nbsp;All</font></a>
</td></tr></table>

' your code here to submit buttom

</form>
</body>
Here' the sample at the bottom . This is a live pager so please don't send a broadcast message.

http://www.servillon.com/paging3/index.html
Reply With Quote
  #3 (permalink)  
Old 01-12-06, 17:33
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
from memory (and with a little trial and error you can test this) if you have multiple check boxes all with the same name/id and different values, when you call the Request object to get the value for the checkboxes (with the duplicate names/ids) you should get a comma delimited string of values.

If these are the ids for the database records you want to delete you can then do something like....
Code:
myIds = Request("chkDelete")
sql= "delete from myTable1 where myTable.Id in ('" + myId's + "')"
dbConnection.Execute(sql)
from memory anyways....
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On