Pagina 1 di 4 1 2 3 ... ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 31
  1. #1

    Edit,Update e Delete con ADO

    Ho trovato questo script sul sito di w3c school quihttp://www.w3schools.com/ado/ado_demo.asp è proprio quello che serve a me,ma nell'ultima fase qualcosa non va...vi posto i lcodice della terza pagina.
    codice:
    <!DOCTYPE html>
    <html>
    <head>
    <title>ADO - Submit DataBase Record</title>
    </head>
    <body>
    <h2>Submit to Database</h2>
    
    <%on error resume next
    set conn=Server.CreateObject("ADODB.Connection") 
    conn.provider="Microsoft.Jet.OLEDB.4.0"
    conn.open(server.mappath("/db/database.mdb"))
    
    if Request.form("action")="Save" then
           no=Request.Form("no")
           sql="UPDATE tblGuestBook SET fname='" & Request.Form("fname") & "',"
           sql=sql & "lname='" & Request.Form("lname") & "',"
           sql=sql & "phone='" & Request.Form("phone") & "',"
           sql=sql & "email='" & Request.Form("email") & "',"
           sql=sql & "homepage='" & Request.Form("homepage") & "',"
           sql=sql & "dateadded='" & now() & "' WHERE tblGuestBook.[no]=" & no
    '  conn.Execute sql, Recordsaffected
    '  if err <> 0 then
    '   Response.Write("You do not have permission to update this database!")
    '  else  
    '   Response.Write("Record number " & no & " was updated.")
    '  end if  
           Response.Write("Submitting records has been disabled from this demo")
    end if
    if Request.Form("action")="Delete" then
           no=Request.Form("no")
    '  conn.Execute "DELETE FROM tblGuestBook WHERE tblGuestBook.[no]=" & no, Recordsaffected
    '  if err <> 0 then
    '   Response.Write("You do not have permission to delete a record from this database!")
    '  else  
    '   Response.Write("Record number " & no & " was deleted.")
    '  end if  
           Response.Write("Deleting records has been disabled from this demo")
    end if
    
    conn.close%>
    
    
    
    View source on how to save changes to, or delete from a database.</p>
    </body>
    </html>

    Sul sito c'è scritto che devo modificare i permessi, però i permessi sono già abilitati, tanto che uso già quella cartella con il database con altre pagine senza ricevere errori,strano?

    ps: Dimentico di dire che anche togliendo i commenti dalla pagine mi restituisce sempre lo stesso errore

  2. #2
    Amministratore L'avatar di Vincent.Zeno
    Registrato dal
    May 2003
    residenza
    Emilia-Romagna (tortellini und cappelletti land!)
    Messaggi
    20,781
    non è chiaro cosa non ti funziona, la cancellazione?

  3. #3
    Originariamente inviato da Vincent.Zeno
    non è chiaro cosa non ti funziona, la cancellazione?
    Per la cancellazione ho l'alternativa, mi restitusice un errore che dice "You do not have permission to delete a record from this database" che è dato con if err <> 0.

    Ho letto la documentazione ed ho visto che bisogna dargli i permessi, ma nonostante ciò continua a non funzionare,quello che mi serve è l'update.

    C'è anche una demo online qui

  4. #4
    Amministratore L'avatar di Vincent.Zeno
    Registrato dal
    May 2003
    residenza
    Emilia-Romagna (tortellini und cappelletti land!)
    Messaggi
    20,781

    Re: Edit,Update e Delete con ADO

    comincia col togliere tutti i commenti
    nella demo, ovviamente, update e delete sono inibiti

    lascia stare la faccenda dei permessi che "di certo" hai salvo configurazioni particolari

  5. #5
    Ho già provato a togliere tutto,anzi ora ti posto il codice che ho ricavato scartando quello inutile presunto
    codice:
    <%on error resume next
    set conn=Server.CreateObject("ADODB.Connection") 
    conn.provider="Microsoft.Jet.OLEDB.4.0"
    conn.open(server.mappath("mdb-database/utenti.mdb"))
    
    if Request.form("action")="Save" then
         	id=Request.Form("id")
         	sql="UPDATE * tabella SET fname='" & Request.Form("fname") & "',"
           sql=sql & "lname='" & Request.Form("lname") & "',"
       WHERE tabella.[id]=" & id"
    	conn.Execute sql, Recordsaffected
    	if err <> 0 then
    	 Response.Write("You do idt have permission to update this database!")
    	else	
    	 Response.Write("Record number " & id & " was updated.")
    	end if	
    end if	%>
    
    
    
    View source on how to save changes to, or delete from a database.</p>
    </body>
    </html>

  6. #6
    Amministratore L'avatar di Vincent.Zeno
    Registrato dal
    May 2003
    residenza
    Emilia-Romagna (tortellini und cappelletti land!)
    Messaggi
    20,781
    posta tutto il codice

  7. #7
    lo è,forse intendi tutte e 3 le pagine:

    1.
    codice:
    <%option explicit%>
    <!DOCTYPE html>
    <html>
    <head><title>ADO - List Database Records</title></head>
    <body>
    <%
    dim conn,rs,x
    set conn=Server.CreateObject("ADODB.Connection") 
    conn.provider="Microsoft.Jet.OLEDB.4.0"
    conn.open(server.mappath("mdb-database/utenti.mdb"))
    set rs=Server.CreateObject("ADODB.Recordset")
    rs.open "SELECT id,tipo,grammatura,formato,totale,data FROM tabella",conn
    %>
    <h2>List Database Table</h2>
    
    <table border="1" width="100%">
    <tr bgcolor="#b0c4de">
    <%
    for each x in rs.Fields
         	response.write("<th>" & ucase(x.name) & "</th>")
    next
    %>
    </tr>
    <%do until rs.EOF%>
    <tr bgcolor="#f0f0f0">
    <form method="post" action="b.asp" target="_blank">
    <%
    for each x in rs.Fields
         	if x.name="id" then%>
              	 <td><input type="submit" name="id" value="<%=x.value%>"></td>
         	<%else%>
              	 <td><%Response.Write(x.value)%> </td>
         	<%end if
    next
    %>
    </form>
    <%rs.MoveNext%>
    </tr>
    <%
    loop
    rs.close
    set rs=idthing
    conn.close
    set conn=idthing
    %>
    </table>
    
    </body>
    </html>
    2
    codice:
    <%
    id=Request.Form("id")
    if id="" then response.end
    set conn=Server.CreateObject("ADODB.Connection") 
    conn.provider="Microsoft.Jet.OLEDB.4.0"
    conn.open(server.mappath("mdb-database/utenti.mdb"))
    set rs = Server.CreateObject("ADODB.Recordset")
    rs.Open "Select * from tabella where tabella.[id]=" & id , conn
    %>
    <!DOCTYPE html>
    <html>
    <head>
    <title>ADO - Edit DataBase Record</title>
    </head>
    <body>
    <h2>Edit Database Table</h2>
    <form method="post" action="c.asp" target="_blank">
    <input name="id" type="hidden" value=<%=id%>>
    <table bgcolor="#b0c4de">
    <%
    for each x in rs.Fields
         	if x.name <> "id" and x.name <> "dateadded" then%>
              	 <tr>
              	 <td><%=x.name%> </td>
              	 <td><input name="<%=x.name%>" value="<%=x.value%>" size="20"></td>
                  
         	<%end if
    next
    
    rs.close
    conn.close
    %>
    </tr>
    </table>
    
    
    <input type="submit" name="action" value="Save">
    <input type="submit" name="action" value="Delete">
    </form>
    
    
    
    </p>
    </body>
    </html>
    3
    codice:
    <html>
    <head>
    <title>ADO - Submit DataBase Record</title>
    </head>
    <body>
    <h2>Databa</h2>
    <%on error resume next
    set conn=Server.CreateObject("ADODB.Connection") 
    conn.provider="Microsoft.Jet.OLEDB.4.0"
    conn.open(server.mappath("mdb-database/utenti.mdb"))
    
    if Request.form("action")="Save" then
         	id=Request.Form("id")
         	sql="UPDATE * tabella SET fname='" & Request.Form("fname") & "',"
           sql=sql & "lname='" & Request.Form("lname") & "',"
       WHERE tabella.[id]=" & id"
    	conn.Execute sql, Recordsaffected
    	if err <> 0 then
    	 Response.Write("You do idt have permission to update this database!")
    	else	
    	 Response.Write("Record number " & id & " was updated.")
    	end if	
    end if%>
    
    
    
    View source on how to save changes to, or delete from a database.</p>
    </body>
    </html>

  8. #8
    Amministratore L'avatar di Vincent.Zeno
    Registrato dal
    May 2003
    residenza
    Emilia-Romagna (tortellini und cappelletti land!)
    Messaggi
    20,781
    intanto correggi questo
    codice:
    WHERE tabella.[id]=" & id"
    con
    codice:
    WHERE [id]=" & id
    oppure
    codice:
    WHERE [id]=" & id & " "
    edit... no, pensavo ci fosse altro. serve solo l'ultima parte

  9. #9
    togli la

    On Error Resume Next

    così ti dice quale è l'errore *vero*

  10. #10
    Grazie per la collaborazione che mi state dando.
    Togliendo on error mi da un errore alla linea 16 che sarebbe

    codice:
    WHERE tabella.[id]=" & id & "

    Modificandolo in WHERE tabella.[id]=" & id & " " o WHERE [id]=" & id Non va lo stesso

    WHERE tabella.[id]=" & id
    -------------------------^

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.