Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2006
    Posts
    10

    Unanswered: 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 10:11.

  2. #2
    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

  3. #3
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    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....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •