records not getting deleted

Discussion in 'C#' started by akinak, Mar 19, 2009.

  1. #1
    I have a SQL query in my ASP code to delete all records from Ms access databse where date=today.

    what happens is I do not see the records on my webpage, but they do no get deleted from the database. And next day, I see those records back on the page. Here is my code:

    <%
    Dim Conn
    Dim rs
    Dim sql
    
    Set Conn = Server.CreateObject("ADODB.Connection")
    
    Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
    Conn.ConnectionString = "Data Source=" & Server.MapPath ("db.mdb")
    Conn.Open
    
    Set rs = Server.CreateObject("ADODB.Recordset") 
    sql = "SELECT record.* FROM record WHERE date=Date();" 
    Rs.Open sql, Conn, 1,3
    Do while not rs.EOF
    rs.delete
    rs.MoveNext
    Loop
    rs.close %>
    Code (markup):
    How can I get the records to be deleted permanently from the database?
     
    akinak, Mar 19, 2009 IP
  2. MayurGondaliya

    MayurGondaliya Well-Known Member

    Messages:
    1,233
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    170
    #2
    Have you tried Conn.execute "DELETE record WHERE date=" + Date() ?? It should work. Make sure that your string concatnation is proper.
     
    MayurGondaliya, Mar 20, 2009 IP
  3. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #3
    add:
    rs.Update

    after rs.Delete
    updating is also essential when adding or editing records.
     
    camjohnson95, Mar 21, 2009 IP
  4. akinak

    akinak Peon

    Messages:
    256
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Mayur..I am not much of a coder..can you please give me a code for what you are trying to say..thanks

    camjohnson95..I added rs.update but it did not work. no record gets deleted from the database.
     
    akinak, Mar 24, 2009 IP
  5. emlak

    emlak Peon

    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    <%
    Set rs = Server.CreateObject("ADODB.Recordset")
    'sql = "delete FROM record WHERE date=Date();"

    sql = "delete FROM record WHERE date="&Date&";"

    ' or use '#"&date&"#' if field type is date
    rs.open sql,conn,1,3
    rs.update
    rs.close %>
     
    emlak, Apr 8, 2009 IP