Estrarre dati da db e modifica

grottafelix

Utente Attivo
5 Mar 2003
2.410
2
38
46
Parco chiuso -
www.girsms.com
allora devo realizzare un applicazione che mi permetta di fare queste cose:

Visualizzare i record di un database
quindi di estrarli
modificarli quando mi pare
e
inserire nuovi record

Sto facendo cosi:

ho creato due file.
il primo "prende" i record:



code:--------------------------------------------------------------------------------
<%
Dim ModID
ModID = Request("id")
if ModID = "" then
ModID = 1
end if

MyDB="database.mdb"
Set conn = Server.CreateObject("ADODB.Connection")
dsnpath = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(myDB)
conn.open dsnpath
querysql="select * from Tabella where id =" & ModID
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open querysql, conn, 3, 3
if rs.eof then
response.write "errore! ID non trovato!"
response.end
end if
%>

<html><head>
<title>Modifica i dati</title>
</head>

<form method="POST" action="salva.asp">
<input type="hidden" name="id" value="<%=ModID%>">
<table>
<tr>
<td>Telefono:</td><td><input type="text" name="nome" size="20" value="<%=Rs("Telefono>"></td>
</tr><tr>
<td>Fax:</td><td><input type="text" name="cognome" size="20" value="<%=rs("Fax")%>"></td>
</tr><tr>
<td>Cell:</td><td><input type="text" name="telefono" size="20" value="<%=rs("Cell")%>"></td>
</tr>
</table>
<input type="submit" value="MODIFICA DATI!">
</form>

<%
rs.close
set rs = Nothing
conn.close
Set conn = Nothing
%>

</body>
</html>

--------------------------------------------------------------------------------


e il secondo file "salva":


code:--------------------------------------------------------------------------------
<%
Dim ModID
ModID = Request.Form("id")

MyDB="database.mdb"
Set conn = Server.CreateObject("ADODB.Connection")
dsnpath = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(myDB)
conn.open dsnpath
Set rs = Server.CreateObject("ADODB.Recordset")
Set rs.ActiveConnection = conn
rs.Open "select * from Tabella where id =" & ModID, ,1,3
rs("Telefono") = Request("Telefono")
rs("Fax") = Request("Faz")
rs("Cell") = Request("Cell")
rs.Update
rs.Close
Set rs = Nothing
conn.close
Set conn = Nothing
%>

<html><head>
<title>Salvataggio dei dati</title>
</head>

<p align=center>
Il database è stato aggiornato.
</p>

</body>
</html>
--------------------------------------------------------------------------------

questi sono i due file con cui andrò a estrarre i dati e a modificarli.


con questa pagina stampa a video tutti i record:

<%
Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & _
Server.MapPath("database.mdb")

Dim objRS
Set objRS = Server.CreateObject("ADODB.RecordSet")
objRS.Open "Tabella", objConn
%>

<%
Do While Not objRS.EOF
Response.Write objRS("Telefono") & " " & objRS("Cell")& "<br>"
objRS.MoveNext
Loop

objRS.Close
Set objRS = Nothing

objConn.Close
Set objConn = Nothing
%>



fin qui tutto bene.
solo che i risultati stampati a video dovrebbere contenere un bottone o cmq dovrebbero essere dei link con l'ID del record che mi interessa.

cosicche clicco su un record stampato e mi accede alla pagina "prendi" dove posso modificarlo.

mi sono bloccato qui :-(
 
Response.Write "<a href=""edit.asp?id=" & objRS("ID") & """>"
Response.Write objRS("Telefono") & " " & objRS("Cell")& "</a><br>"
 
grazie jaco.

allora SEMBRA funzionare tutto bene..infatti mi dice pure database aggiornato quando faccio delle modifiche ai record....
ma poi...quando apro il browser le modifiche non rislutano.
Il bello è che non risultano nenache nel db.
ma allora che fa qeusto script?? mi prende in giro???:( :(

help me
 
felix ma tu per modificare i tuoi dati usi questo:
<%
Dim ModID
ModID = Request.Form("id")

MyDB="database.mdb"
Set conn = Server.CreateObject("ADODB.Connection")
dsnpath = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(myDB)
conn.open dsnpath
Set rs = Server.CreateObject("ADODB.Recordset")
Set rs.ActiveConnection = conn
rs.Open "select * from Tabella where id =" & ModID, ,1,3
rs("Telefono") = Request("Telefono")
rs("Fax") = Request("Faz")
rs("Cell") = Request("Cell")
rs.Update
rs.Close
Set rs = Nothing
conn.close
Set conn = Nothing
%>

?? Se si ti consiglio di usare "UPDATE"... lo hanno inventato apposta :p
 
Codice:
"UPDATE Tabella
SET Telefono = '" & Request("Telefono") & "',
       Fax   = '" & Request("Faz") & "',
       Cell  = '" & Request("Cell") & "'
WHERE id = " & ModID
Questa e` la Query Sql
 
Vedi perche` io non ti voglio dare il code? Perche` senno` farai sempre sta diavolo di domanda e non riuscirai mai ad aver piu` conoscienze!
Comunque:
Codice:
<%
Set strConn = Server.CreateObject("ADODB.Connection")
    strConn.Open "Driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath(myDB)
Set strRs = Server.CreateObject("ADODB.Recordset")
    strSql = "UPDATE Tabella
              SET Telefono = '" & Request("Telefono") & "',
                  Fax   = '" & Request("Faz") & "',
                  Cell  = '" & Request("Cell") & "'
              WHERE id = " & ModID
    strRs.Open strSql, strConn
    strRs.Close
Set strRs = Nothing
    strConn.Close
Set strConn = Nothing	
%>
Bye :byebye:
 
si ma continuo a non capire...sarò di coccio..ma continuo a non capire.

ma devo eliminare il file salva_dati.asp?
o questo codice lo devo aggiungere a quello?

devo fare cosi:

<%
Dim ModID
ModID = Request.Form("id")

MyDB="database.mdb"
<%
Set strConn = Server.CreateObject("ADODB.Connection")
strConn.Open "Driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath(myDB)
Set strRs = Server.CreateObject("ADODB.Recordset")
strSql = "UPDATE Tabella
SET Telefono = '" & Request("Telefono") & "',
Fax = '" & Request("Fax") & "',
Cell = '" & Request("Cell") & "'
WHERE id = " & ModID
strRs.Open strSql, strConn
strRs.Close
Set strRs = Nothing
strConn.Close
Set strConn = Nothing
%>

<html><head>
<title>Salvataggio dei dati</title>
</head>

<p align=center>
Il database è stato aggiornato.
</p>

</body>
</html>


????:(
 
mi da questo errore:

Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

/salva_dati1.asp, line 7

la linea 7 è quella della connessione al db!
che succede??:(
 
<%
Dim ModID
ModID = Request.Form("id")

MyDB="database.mdb"
Set strConn = Server.CreateObject("ADODB.Connection")
strConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(myDB)
Set strRs = Server.CreateObject("ADODB.Recordset")
strSql = "UPDATE Tabella SET Tel = '" & Request("Tel") & "', Cell = '" & Request("Cell") & "', Fax = '" & Request("Fax") & "' WHERE id = " & ModID
strRs.Open strSql, strConn
strRs.Close
Set strRs = Nothing
strConn.Close
Set strConn = Nothing
%>

<html><head>
<title>Salvataggio dei dati</title>
</head>

<p align=center>
Il database è stato aggiornato.
</p>

</body>
</html>


dove sabglio???
 
Ultima modifica:

Discussioni simili