Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    Inserimento dati in un database Access

    Ciao!!
    Ho un problema a far funzionare una pagina per l'inserimento di dati in un DB access.. questo il codice dellìintera pagina:

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Documento senza titolo</title>

    <style type="text/css">
    <!--
    .Stile1 {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 12px;
    }
    -->
    </style>
    </head>

    <body>
    <%
    if request("id")=1 then
    on error resume next
    dim strQuery
    strQuery="INSERT INTO tabella("
    dim strValori
    strValori=" VALUES("
    dim strSql
    strSql=""

    for each item in request.form
    if item<>"Submit" then
    strQuery= strQuery & item &","
    strValori= strValori & "'"&server.HTMLEncode(request.form(item))&"',"
    end if
    next

    strQuery=mid(strQuery,1,len(strQuery)-1) &")"
    strValori=mid(strValori,1,len(strValori)-1) &")"

    set rs =server.createObject("ADODB.Recordset")
    strConn="driver={Microsoft Access Driver (.mdb)}; "
    strConn=strConn & " DBQ=" & Server.MapPath("database.mdb")
    set cn = Server.CreateObject("ADODB.Connection")
    cn.Open strConn
    strSql= strQuery & strValori
    rs.open strSql,cn
    set rs=nothing
    if err.number<>0 then
    response.write err.number &"
    "&err.description
    else
    response.write "inserimento avvenuto con successo"
    end if

    response.end
    end if
    %>
    <form method="post" action="Invio.asp?id=1">
    <span class="Stile1">Nome:
    <input type="text" name="Nome">


    Cognome:
    <input type="text" name="Cognome">


    Nick:
    <input type="text" name="Nick">
    </span>

    <input type="submit" name="Submit" value="Invia">
    </form>
    </body>
    </html>

    L'errore restituito è:

    3709
    Connessione chiusa o non valida in questo contesto. Impossibile utilizzarla per eseguire l'operazione.

    Mi hanno consigliati di eliminare la riga
    on error resume next
    per vedere la riga che genera l'errore.. l'ho fatto e la riga incriminata risuta questa
    cn.Open strConn

    Premetto che il percorso del database è giusto..
    ..avete qualche idea su come risolvere il problema?

    Ringrazio anticipatamente tutti,
    ciao

  2. #2
    Utente di HTML.it L'avatar di wegawhite
    Registrato dal
    Aug 2004
    Messaggi
    1,400
    Prova così:
    codice:
    <html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
    <title>Documento senza titolo</title> 
    
    <style type="text/css"> 
    <!-- 
    .Stile1 { 
    font-family: Verdana, Arial, Helvetica, sans-serif; 
    font-size: 12px; 
    } 
    --> 
    </style> 
    </head> 
    
    <body> 
    <% 
    if request("id")=1 then 
     
    dim strQuery 
    strQuery="INSERT INTO tabella(" 
    dim strValori 
    strValori=" VALUES(" 
    dim strSql 
    strSql="" 
    
    for each item in request.form 
    if item<>"Submit" then 
    strQuery= strQuery & item &"," 
    strValori= strValori & "'"&server.HTMLEncode(request.form(item))&"'," 
    end if 
    next 
    
    strQuery=mid(strQuery,1,len(strQuery)-1) &")" 
    strValori=mid(strValori,1,len(strValori)-1) &")" 
    
    set rs =server.createObject("ADODB.Recordset") 
    
    Set cn = Server.CreateObject("ADODB.Connection")
    OpenStr = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.Mappath("db2.mdb")
    cn.Open openStr
    
    
    strSql= strQuery & strValori 
    rs.open strSql,cn 
    set rs=nothing 
    if err.number<>0 then 
    response.write err.number &"
    "&err.description 
    else 
    response.write "inserimento avvenuto con successo" 
    end if 
    
    response.end 
    end if 
    %> 
    <form method="post" action="Invio.asp?id=1"> 
    <span class="Stile1">Nome: 
    <input type="text" name="Nome" size="20"> 
    
     
    Cognome: 
    <input type="text" name="Cognome" size="20"> 
    
     
    Nick: 
    <input type="text" name="Nick" size="20"> 
    </span>
     
    <input type="submit" name="Submit" value="Invia"> 
    </form> 
    </body> 
    </html>

  3. #3
    Ora mi dice questo:

    Microsoft OLE DB Provider for ODBC Drivers error '80004005'

    [Microsoft][Driver ODBC Microsoft Access] Per l'operazione è necessaria una query aggiornabile.

    /DB/invio.asp, line 45


    Dove la riga 45 è

    rs.open strSql,cn



  4. #4
    Utente di HTML.it L'avatar di albis
    Registrato dal
    May 2002
    Messaggi
    912
    la cartella che contiene il db deve avere i permessi di scrittura per l'internetGuest
    Forza la magica ROMA

  5. #5
    Sì è la cartella di un sito che uso già per database access... lettura, scrittura, modifica.. quindi i permessi sono ok..

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.