41 messaggi dal 20 giugno 2001
io ho questo script che in teoria dovrebbe servire per gestire un db (aggiungere, modificare cancellare record):
---------------------------------------------
<html>
<head>
<title>Gestione Database</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<%@ Language=VBScript %>
<%
Function Apex(sData,newData)
' Return string with single quotes doubledDim iLast As Integer
If Len(sData) = 0 Then
NewData = ""
Exit Function
END IF
iLast = InStr(sData, "'")
While iLast
sPart = sPart & left(sData, iLast - 1) & "'" & "'"
sData = Right(sData, Len(sData) - iLast)
iLast = InStr(sData, "'")
Wend
sData = sPart & sData
newData = Trim(sData)
End Function

'Create object. In this case Connection to a database
Set Conn = Server.CreateObject("ADODB.Connection")

'Select provider
Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
'Select data source.
'Server.MapPath function is equivalent to app.path function of VB
'It returns the directory in which the script is present
Conn.ConnectionString = "Data Source=" & Server.MapPath ("/mdb-database/autosuper_97.mdb")
'Open the connection
Conn.Open

'Create recordset
Set Rs = Server.CreateObject("ADODB.Recordset")
Set mTable = Server.CreateObject("ADOX.Catalog")
set mNew = Server.CreateObject("ADOX.Table")
'Open recordset with the connection which we have created earlier
'you must be familiar with SELECT statement ,
'If not check my VB tutorial section.
mtable.ActiveConnection = Conn.ConnectionString
TabellaDaVisualizzare = Request.querystring("Tabella")
if TabellaDaVisualizzare = "" then
TabellaDaVisualizzare = Request.form("Tabella")
end if
SQL =Request.querystring("sSQL")

%>
<body bgcolor="#000080">
<%
if TabellaDaVisualizzare = "" then
%>
<form method="POST" action="GestioneDatabase.asp?TOP=10" id=form2 name=form2>
<font face="Verdana, Arial, Helvetica, sans-serif" size="-1" color="#FFFFFF">
Tabella
</font>

<select name="Tabella" size="1">
<%
i=0
while i < mtable.Tables.Count
if mTable.Tables(i).type = "TABLE" then
%>
<option value=<%= mTable.Tables(i).name%> selected> <%
Response.Write mTable.Tables(i).name
%> </option>
<%
end if
i=i 1
wend
%>
</select>
<br>
<br>
<input type="submit" value="Visualizza" name="Visualizza">
</form>
<%
'Deinitialize the Connection and Recordset
end if
if TabellaDaVisualizzare <> "" then
if Request.querystring("Action") = "" Then
Rs.Open "SELECT TOP " & Request.QueryString ("TOP") & " * from " & TabellaDaVisualizzare, Conn, 1,3
set mNew = mtable.tables(TabellaDaVisualizzare)
%>

<table width="98%" border="1">
<tr>
<td colspan=<%response.write mnew.columns.count 2%>>
<div align="center">
<font face="Verdana, Arial, Helvetica, sans-serif" size=" 1" color="#FFFFFF">
<b>
<%
response.write "Gestione Tabella " & mNew.name
%>
</b>
</font>
</div>
</td>
</tr>
<tr>
<td> 

</td>
<td> 

</td>
<%
i=0
while i < mNew.columns.count
%>
<td>
<div align="center">
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="-1" color="#FFFFFF">
<%
response.write mNew.columns(i).name
%>
</font></p>
</div>
</td>
<%
i=i 1
wend
%>
</tr>
<%
t=0
lTop = clng(Request.QueryString("TOP")) - 9
t =1
while not rs.EOF and t < ltop
t=t 1
rs.MoveNext
wend
while not rs.eof
i=0
sWhere = ""
if mNew.Indexes.count > 0 then
while i < mNew.indexes(0).columns.count
if swhere = "" then
sWhere = "WHERE " & mnew.columns(mNew.indexes(0).columns(i).name).name & " = "
else
sWhere = sWhere & " AND " & mnew.columns(mNew.indexes(0).columns(i).name).name & " = "
end if
select case mnew.columns(mNew.indexes(0).columns(i).name).type
case 11,3
sWhere = swhere & rs(mNew.indexes(0).columns(i).name)
case 202,203
apex rs(mNew.indexes(0).columns(i).name),sString
sWhere = swhere & "'" & sString & "'"
case 7
sWhere = swhere & "#" & rs(mNew.indexes(0).columns(i).name) & "#"
end select
i=i 1
wend
else
while i < mNew.columns.count
if swhere = "" then
sWhere = "WHERE " & mnew.columns(i).name & " = "
else
sWhere = sWhere & " AND " & mnew.columns(i).name & " = "
end if
select case mnew.columns(i).type
case 11,3
sWhere = swhere & rs(mnew.columns(i).name)
case 202,203
apex rs(mnew.columns(i).name),sString
sWhere = swhere & "'" & sString & "'"
case 7
sWhere = swhere & "#" & rs(mnew.columns(i).name) & "#"
end select
i=i 1
wend
end if
%>

<tr>

<td>
<div align="center">
<a href=<%= "GestioneDatabase.asp?Tabella="& TabellaDaVisualizzare & "&Action=Aggiorna&Query=" & server.URLEncode(swhere)& "&TOP=" & clng(Request.QueryString ("TOP"))%>><img src="Immagini/prop.gif" width="18" height="16" border="0" alt=Aggiorna></a>
</div>
</td>
<td>
<div align="center">
<a href=<%= "GestioneDatabase.asp?Tabella="& TabellaDaVisualizzare & "&Action=Cancella&Query=" & server.URLEncode("DELETE * FROM " & TabellaDaVisualizzare & " " & swhere) & "&TOP=" & clng(Request.QueryString ("TOP"))%>><img src="Immagini/delx.gif" width="18" height="16" border="0" alt=Aggiorna></a>
</div>
</td>
<%
i=0
while i < mNew.columns.count
%>
<td>
<font face="Verdana, Arial, Helvetica, sans-serif" size="-1" color="#FFFFFF">
 
<%= rs(mNew.columns(i).name)%>
</font>
</td>

<%
i=i 1
wend
%>
</tr>
<%
rs.movenext
t=t 1
wend
%>
</table>

<table width=98 border=0 height=35>
<tr>

<td align=center height="45" valign="bottom">
<form method="POST" action=<%= "GestioneDatabase.asp?Tabella="& TabellaDaVisualizzare & "&Action=Aggiungi" & "&TOP=" & clng(Request.QueryString ("TOP"))%> id=form3 name=form3>
<input type="submit" value="Aggiungi" name="B1">
</form>
</td>
<td align=center height="45" valign="top">
<%
if (ltop 9) = rs.RecordCount then
%>
<a href=<%= "GestioneDatabase.asp?Tabella="& TabellaDaVisualizzare & "&TOP=" & clng(Request.QueryString ("TOP")) 10 %>><img src="Immagini/Forward_Color.gif" width=32 height=29 border="0" alt="Successivi 10" align=middle></a>
<%
end if
%>
</td>
</tr>
</table>
<%
else
select case Request.querystring("Action")
case "Cancella"
Conn.Execute Request.querystring("Query")
Response.Redirect "GestioneDatabase.asp?Tabella=" & TabellaDaVisualizzare & "&TOP=" & clng(Request.QueryString ("TOP"))
case "Aggiorna"
rs.Open "SELECT * FROM " & TabellaDaVisualizzare & " " & Request.querystring("Query"),conn,1,3
set mNew = mtable.tables(TabellaDaVisualizzare)
%>
<table width="98%" border="1">
<tr>
<td colspan=<%response.write mnew.columns.count 1%>>
<div align="center">
<font face="Verdana, Arial, Helvetica, sans-serif" size=" 1" color="#FFFFFF">
<b>
<%
response.write "Gestione Tabella " & mNew.name
%>
</b>
</font>
</div>
</td>
</tr>
<tr>
<td>
</td>
<%
i=0
while i < mNew.columns.count
if not mNew.columns(i).Properties(0) then
%>

<td>
<div align="center">
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="-1" color="#FFFFFF">
<%
response.write mNew.columns(i).name
%>
</font></p>
</div>
</td>
<%
end if
i=i 1
wend
%>

<tr>
<form method="POST" action=<%response.write "GestioneDatabase.asp?Tabella="& TabellaDaVisualizzare & "&Action=SalvaModifiche&Query=" & server.URLEncode(Request.querystring("Query")) & "&TOP=" & clng(Request.QueryString ("TOP"))%> id=form1 name=form1>
<td>
<input type="submit" value="Salva" name="B1">
</td>
<%
i=0
while i < mNew.columns.count
if not mNew.columns(i).Properties(0) then
%>

<td>
<input type="Text" name="<%= mNew.columns(i).name%>" value="<%= rs(mNew.columns(i).name) %>" style="WIDTH: 100%; HEIGHT: 100%; BACKGROUND-COLOR: silver">
</td>
<%
end if
i=i 1
wend
%>
</form>
</tr>
</table>
<%
case "Aggiungi"
set mNew = mtable.tables(TabellaDaVisualizzare)
%>
<table width="98%" border="1">
<tr>
<td colspan=<%response.write mnew.columns.count 1%>>
<div align="center">
<font face="Verdana, Arial, Helvetica, sans-serif" size=" 1" color="#FFFFFF">
<b>
<%
response.write "Gestione Tabella " & mNew.name
%>
</b>
</font>
</div>
</td>
</tr>
<tr>
<td>
</td>
<%
i=0
while i < mNew.columns.count
if not mNew.columns(i).Properties(0) then
%>

<td>
<div align="center">
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="-1" color="#FFFFFF">
<%
response.write mNew.columns(i).name
%>
</font></p>
</div>
</td>
<%
end if
i=i 1
wend
%>

<tr>
<form method="POST" action=<%response.write "GestioneDatabase.asp?Tabella="& TabellaDaVisualizzare & "&Action=Salva" & "&TOP=" & clng(Request.QueryString ("TOP"))%> id=form4 name=form4>
<td>
<input type="submit" value="Salva" name="B1">
</td>
<%
i=0
while i < mNew.columns.count
if not mNew.columns(i).Properties(0) then
%>

<td>
<input type="Text" name="<%= mNew.columns(i).name%>" style="WIDTH: 100%; HEIGHT: 100%; BACKGROUND-COLOR: silver">
</td>
<%
end if
i=i 1
wend
%>
</form>
</tr>
</table>
<%
case "Salva"
set mNew = mtable.tables(TabellaDaVisualizzare)
i=0
sInsert = ""
while i < mNew.columns.count
if sInsert = "" then
sInsert = ") VALUES ("
sCampo = "INSERT INTO " & TabellaDaVisualizzare & "("
select case mNew.columns(i).type
case 11,3
if not mNew.columns(i).Properties(0) then
sCampo = sCampo & mNew.columns(i).name
sInsert = sInsert & request.form(mNew.columns(i).name)
end if
case 202,203
sCampo = sCampo & mNew.columns(i).name
apex request.form(mNew.columns(i).name),sString
sInsert = sInsert & "'" & sString & "'"
case 7
sCampo = sCampo & mNew.columns(i).name
sInsert = sInsert & "#" & request.form(mNew.columns(i).name) & "#"
end select
else
select case mNew.columns(i).type
case 11,3
if not mNew.columns(i).Properties(0) then
sCampo = sCampo & "," & mNew.columns(i).name
sInsert = sInsert & "," & request.form(mNew.columns(i).name)
end if
case 202,203
sCampo = sCampo & "," & mNew.columns(i).name
apex request.form(mNew.columns(i).name),sString
sInsert = sInsert & ",'" & sString & "'"
case 7
sCampo = sCampo & mNew.columns(i).name
sInsert = sInsert & "#" & request.form(mNew.columns(i).name) & "#"
end select
end if
i=i 1
wend
Conn.Execute sCampo & sInsert & ")"
Response.Redirect "GestioneDatabase.asp?Tabella=" & TabellaDaVisualizzare & "&TOP=" & clng(Request.QueryString ("TOP"))
case "SalvaModifiche"
set mNew = mtable.tables(TabellaDaVisualizzare)
i = 0
sUpdate = ""
while i < mNew.columns.count
select case mnew.columns(i).type
case 11,3
if not mNew.columns(i).Properties(0) then
if sUpdate = "" then
sUpdate ="UPDATE " & TabellaDaVisualizzare & " SET " & mnew.columns(i).name & "=" & request.form(mnew.columns(i).name)
else
sUpdate=sUpdate & "," & mnew.columns(i).name & "=" & request.form(mnew.columns(i).name)
end if
end if
case 202,203
if sUpdate = "" then
apex request.form(mnew.columns(i).name),sString
sUpdate="UPDATE " & TabellaDaVisualizzare & " SET " & mnew.columns(i).name & " = '" & sString & "'"
else
apex request.form(mnew.columns(i).name),sString
sUpdate=sUpdate & "," & mnew.columns(i).name & "='" & sString & "'"
end if
case 7
if sUpdate = "" then
sUpdate ="UPDATE " & TabellaDaVisualizzare & " SET " & mnew.columns(i).name & "=#" & request.form(mnew.columns(i).name) & "#"
else
sUpdate=sUpdate & "," & mnew.columns(i).name & "=#" & request.form(mnew.columns(i).name) & "#"
end if
end select
i=i 1
wend
if sUpdate <> "" then
Conn.Execute sUpdate & " " & Request.querystring("Query")
Response.Redirect "GestioneDatabase.asp?Tabella=" & TabellaDaVisualizzare & "&TOP=" & clng(Request.QueryString ("TOP"))
end if
end select
end if
end if
set Rs = nothing
set Conn = nothing
%>
</body>
</html>
---------------------------------------------
Il problema è che quando provo ad eseguire una modifica mi da il seguente errore:
---------------------------------------------
ADODB.Field error '80020009'

Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

?
---------------------------------------------
quando provo a cancellare invece mi dice:
---------------------------------------------
Response object error 'ASP 0156 : 80004005'

Header Error

/GestioneDatabase.asp, line 237

The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content.
---------------------------------------------
Microsoft JET Database Engine error '80040e14'

Syntax error in INSERT INTO statement.

/GestioneDatabase.asp, line 407
---------------------------------------------
Chi mi puo aiutare?

come firma?
409 messaggi dal 11 maggio 2001
Non ti sembra di avere esagerato!
Concordo con Grigno.

<b>E' una cosa inutile inserire un listato così lungo</b>.
Esisitono delle FAQ che dovrebbero essere state lette da tutti (mi sa che le manderò a cadenza settimanale) che spiegano come partecipare a questo forum.

Spero che anche tu le vada a leggere.

<b>Il Link alle FAQ è presente in alto "Prima di postare.."</b>

Grazie


<b>Andrea Palmatè</b>
<i>ASPITALIA.com</i>

Modificato - Andrea Palmatè - 04 Lug 2001 09:30:53

--
Andrea Palmatè
41 messaggi dal 20 giugno 2001
Scusate ragazzi ma il caldo e la disperazione con queste asp mi hanno portato a tutto ciò!Scusate di nuovo.

come firma?
69 messaggi dal 28 maggio 2001
Io uso il tableeditor 0.7 e mi trovo bene, anche perché dopo averlo configurato ti permette di modificare anche database dallo stesso pannello.
Guarda qui:
http://www.2enetworx.com/dev/projects/tableeditor.asp

Se poi hai bisogno di aiuto, chiedi pure.

Caio


32 messaggi dal 03 luglio 2001
ciao
effettivamente scrivere tutto il codice confonde non poco.
sugli errori che ti dà il tuo codice il primo:
ADODB.Field error '80020009'
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
in genere indica che non ci sono record nella query che hai richiesto. prova a chiedere un recordcount, se è uguale a zero è la query, senno non so.
per il secondo
The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content.
E' un errore parecchio antipatico che si riferisce a response.redirect
devi inserire nella prima riga della pagina,
mi raccomando prima ancora del HTML, la riga response.buffer=true e prima del redirect response.clear. così dovrebbe funzionare.
attenzione che quello che viene fatto prima viene eseguito.
ciao

64 messaggi dal 25 settembre 2006
Ciao Caio,

io ho scaricato la ver. 081 ma ho problemi di connessione. mi puoi aiutare?

errore:

Microsoft JET Database Engine error '80040e09'

Cannot update. Database or object is read-only.

/adm/te_addDB.asp, line 251

Quando vario qualcosa nell'Edit Database

GuidoC
64 messaggi dal 25 settembre 2006
possibile che non c'è nessuno che mi risponde?

GuidoC

Torna al forum | Feed RSS

ASPItalia.com non è responsabile per il contenuto dei messaggi presenti su questo servizio, non avendo nessun controllo sui messaggi postati nei propri forum, che rappresentano l'espressione del pensiero degli autori.