Ciao a tutti.... premetto che non conosco ASP.... ma avevo giusto bisogno di effettuare delle query sul DB di un sito attraverso appunto una pagina ASP.
Cercando ho trovato lo script che vi riporto qui sotto (ci sono anche i link di dove l'ho trovato)
Per funzionare...mi pare funzioni... si collega al DB e una semplice SELECT me la fa.
Il mio problema è che dovrei letteralmente spostare/copiare dei dati da una tabella A a una tabella B
l'unico problema è che non mi funziona... forse dipende dalla query.. che è questa:
per sicurezza però posto anche il codice della pagina... che cmq potrebbe essere utile anche ad altri.Codice PHP:INSERT INTO [FILES_ARCHIVIO] (data,area,sezione,zona,tipologia,descrizione,link)
SELECT data,area,sezione,zona,tipologia,descrizione,replace(link,'../../files/','../../public/archivio/' as Link FROM [FILES]
Codice PHP:<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
' Recupera i parametri speciali
strSQL = Trim(Request.Form("textfield"))
Conn_STRING = "dsn=db_test;"
%>
<html>
<head>
<title>Gestione DB onLine</title>
<script language="JavaScript">
function impostaquery(){
var scelta = document.form1.selezione.options[document.form1.selezione.selectedIndex].value;
document.form1.textfield.value = scelta
}
</script>
</head>
<body>
Gestione diretta database</p>
<form name="form1" method="post" action="archiviazione_documenti.asp">
<table border="0" cellspacing="2" cellpadding="4">
<tr align="center">
<td colspan="2">
<textarea name="textfield" cols="80" rows="5"><%= strSQL %></textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<select name="selezione" onChange="impostaquery();return true;">
<option value="">QUERY PRE-IMPOSTATE</option>
<option value="SELECT * FROM [NomeTabella]">Tutti i dati inseriti dal primo all'ultimo</option>
<option value="SELECT * FROM [NomeTabella] order by [NomeCampoID] DESC">Tutti i dati inseriti dall'ultimo al primo</option>
<option value="INSERT INTO [NomeTabella] ([ElencoCampi]) VALUES ([ElencoValori])">Insert dati</option>
<option value="UPDATE [NomeTabella] SET [NomeCampo] = [ValoreCampo] WHERE [NomeCampo] = [ValoreCampo]">Update dati</option>
<option value="DELETE FROM [NomeTabella] WHERE [NomeCampo] = [ValoreCampo]">Delete dati</option>
</select>
</td>
</tr>
<tr>
<td width="250" align="center">
<input type="submit" name="Submit" value="Esegui SELECT">
</td>
<td width="250" align="center">
<input type="submit" name="Submit2" value="Esegui COMMAND">
</td>
</tr>
</table>
</form>
<%
If Trim(Request.Form("submit")) <> "" and Trim(strSQL) <> "" then
Dim intNumDati
Set objRs = Server.CreateObject("ADODB.Recordset")
objRs.ActiveConnection = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("/mdb-database/database.mdb")
objRs.CursorType = 0
objRs.CursorLocation = 2
objRs.LockType = 3
objRs.Source = strSQL
objRs.Open()
ntNumDati = 0
If objRs.EOF and objRs.BOF then
Response.write "Nessun dato trovato"
Else
Response.write "<table>"
Response.write "<tr>"
For Each DatoDB In objRs.Fields
Response.write "<td bgcolor='#fac574'>" & DatoDB.Name & "</th>"
Next
Response.write "</tr>"
Do While Not objRs.EOF
' Incrementa il valore della variabile di conteggio dei recordset
intNumDati = intNumDati + 1
Response.write "<tr>"
For Each DatoDB in objRs.Fields
If Not isNull(DatoDB.Value) then
Response.write "<td bgcolor='#ffffb9'>" & DatoDB.Value & "</td>"
Else
Response.write "<td bgcolor='#ffffb9'>[i](Null)[/i]</td>"
End If
Next
Response.write "</tr>"
objRs.MoveNext
Loop
Response.write "</table>"
Response.write "Numero di dati: " & FormatNumber(intNumDati,0)
End If
objRs.Close()
Set objRs = Nothing
End If
If Trim(Request.Form("submit2")) <> "" and Trim(strSQL) <> "" then
Set objEsegui = Server.CreateObject("ADODB.Command")
objEsegui.ActiveConnection = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("/mdb-database/database.mdb")
objEsegui.CommandText = strSQL
objEsegui.Execute
objEsegui.ActiveConnection.Close
Set objEsegui = Nothing
Response.write "La query [b]" & strSQL & "[/B] è stata eseguita"
End If
%>
</td>
</tr>
</table>
</body>
</html>

Rispondi quotando
...scusa l'ignoranza galattica...ma non lo so..