Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 20
  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2006
    Messaggi
    105

    funzione replace per tutti i campi di una tabella...

    ciao...allora io ho la seguente funzione di modifica dei campi di una tabella....
    codice:
    Sub EditItem()
    
    	Response.write ("<h2>Modifica record nella tabella " & strTable & "</h2>")
    	
    	which=request("which")
    	
    	if isNumeric(which) then
    		MySQL="SELECT * FROM " & strTable & " Where " & strKey & " = " & which
    	else
    		MySQL="SELECT * FROM " & strTable & " Where " & strKey & " = '" & which & "'"
    	end if
    	Set MyRs=MyConn.Execute(MySQL)
    
    	Response.write ("<FORM ACTION=""" & strFile & "?mode=EditItemAction"" METHOD=POST>")
    	Response.write ("<input name=""ID"" type=""hidden"" value=""" & MyRs(strKey) & """>")
    	Response.write ("<table>")
    
    	numerocampi=MyRs.fields.count -1
    	
    	for i=0 to numerocampi
    	
    	if Not MyRs(i).name = "ID" then
    		ThisRecord = MyRs(i)
    		ThisRecordName = MyRs(i).name
    		If IsNull(ThisRecord) or ThisRecord = "" Then
    			ThisRecord = ""
    		end if 
    	Response.write ("<tr>")
    	Response.write ("<td height =""auto"" align=""right"">" & ThisRecordName & ": </td>")
    	Response.write ("<td> <input name=""" & ThisRecordName & """ type=""text"" value=""" & MyRs(i) & """></td>")
    	Response.write ("</tr>")
    	end if
    	next
    
    	Response.write ("<tr>")
    	Response.write ("<td align=""right""><INPUT NAME=""Submit"" TYPE=Submit Value=""Update""></td>")
    	Response.write ("<td><INPUT NAME=""Reset"" TYPE=Reset Value=""Reset""></td>")
    	Response.write ("</tr>")
    	Response.write ("</table>")
    	Response.write ("</FORM>")
    
    	Response.write ("Torna alla lista dei record")
    		
    	MyRs.close
    	Set MyRs= Nothing
    
    End Sub
    
    
    Sub EditItemAction()
    
    	which = Request(strKey)
    	which=replace which("'","''")
    	if isNumeric(which) then
    		MySQL="SELECT * FROM " & strTable & " Where " & strKey & " = " & which
    	else
    		MySQL="SELECT * FROM " & strTable & " Where " & strKey & " = '" & which & "'"
    	end if
    
    	'MySQL="Select * from " & strTable
    	Set MyRs=MyConn.Execute(MySQL)
    
    	numerocampi=MyRs.fields.count -1
    
    	for i=0 to numerocampi
    		if Not MyRs(i).name = "ID" then	
    			str = MyRs(i).name 
    			strNames = Request(str)
    			if not i = numerocampi then
    				str1 = str1 & "[" & str & "] = '" & strNames & "', "
    			else
    				str1 = str1 & "[" & str & "] = '" & strNames & "'"
    			end if
    		end if
    	next
    
    	if isNumeric(which) then
    		MySQL1="UPDATE " & strTable & " SET " & str1 & " Where " & strKey & " = " & which
    	else
    		MySQL1="UPDATE " & strTable & " SET " & str1 & " Where " & strKey & " = '" & which & "'"
    	end if
    
    	'MySQL1="UPDATE " & strTable & " SET " & str1 & " Where ID=" & which
    
    	Set MyRs1=MyConn.Execute(MySQL1)
    	
    	MyConn.Close
    	set MyConn=nothing
    	
    	Response.Redirect strFile
    
    End Sub
    come modifico con replace per far si che l'utente quando aggiorna il campo possa scrivere anche l'apostrofo altrimenti dà errore???
    grazie 1000

  2. #2
    codice:
    variabile = replace(variabile,"'","''")

  3. #3
    Utente di HTML.it
    Registrato dal
    Oct 2006
    Messaggi
    105
    Originariamente inviato da Domenix
    codice:
    variabile = replace(variabile,"'","''")
    si ti ringrazio...questo lo avevo studiato...il problema è che,non avendo fatto io lo script ma essendo funzionante su aruba...tra l'altro è un loro esempio... non riesco ora a capire qual'è la variabile che prende tutti i campi... anzi a dire il vero ho scritto forse una fesseria che non c'era nello script in origine...cioè non ci sarebbe quel:
    codice:
    Sub EditItemAction()
    
    	which = Request(strKey)
    	which=replace which("'","''") 
    	if isNumeric(which) then

  4. #4
    Hai notato le parentesi tra il mio esempio e il tuo codice in grassetto?
    Noti qualche differenza?
    Ad ogni modo:
    codice:
    	if isNumeric(which) then
    		MySQL1="UPDATE " & strTable & " SET " & str1 & " Where " & strKey & " = " & which
    	else
    		which = replace(which,"'","''")
    		MySQL1="UPDATE " & strTable & " SET " & str1 & " Where " & strKey & " = '" & which & "'"
    	end if
    Così evitiamo di fare notte.

  5. #5
    Utente di HTML.it
    Registrato dal
    Oct 2006
    Messaggi
    105
    Originariamente inviato da Domenix
    Hai notato le parentesi tra il mio esempio e il tuo codice in grassetto?
    Noti qualche differenza?
    si certo...volevo far vedere appunto che avevo sbagliato...il problema è che non ho capito se è corretto in ogni caso perchè anche scrivendolo
    giusto:
    codice:
    which = replace(which,"'","''")
    mi fa vedere i record ma addirittura non mi funziona + neanche la modifica con caratteri normali... mi dà errore 500
    forse non riesco ad interpretare il codice...mi aiuteresti?? sono esaurito

  6. #6
    Utente di HTML.it
    Registrato dal
    Oct 2006
    Messaggi
    105
    Originariamente inviato da Domenix
    Hai notato le parentesi tra il mio esempio e il tuo codice in grassetto?
    Noti qualche differenza?
    Ad ogni modo:
    codice:
    	if isNumeric(which) then
    		MySQL1="UPDATE " & strTable & " SET " & str1 & " Where " & strKey & " = " & which
    	else
    		which = replace(which,"'","''")
    		MySQL1="UPDATE " & strTable & " SET " & str1 & " Where " & strKey & " = '" & which & "'"
    	end if
    Così evitiamo di fare notte.
    cioè va solo lì la mia modifica??? cioè se non si tratta di un numero...questo l'ho capito
    o anche in UPDATE?? NO ...scusa è già update...si vede che sono esaurito

  7. #7
    Dalle opzioni avanzate di explorer TOGLI la spunta dalla voce Mostra messaggi di errore HTTP brevi.
    Ho editato la mia precedente risposta aggiungendo un blocco di codice tuo modificato da me.

  8. #8
    Utente di HTML.it
    Registrato dal
    Oct 2006
    Messaggi
    105
    Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

    [Microsoft][ODBC Microsoft Access Driver] Syntax error in string in query expression ''afgafgfagf e'', [bio] = '', [productions] = '', [charts] = '' Where ID = 9'.

    /...data/pannello.asp, line 286

    vuoi che ti posti il codice completo???

    e poi come faccio per far in modo che anche nel campo di modifica si veda il record com'era in origine con il campo che si dimensiona in automatico???

  9. #9
    Utente di HTML.it
    Registrato dal
    Oct 2006
    Messaggi
    105
    CODICE COMPLETO:
    codice:
    <%
    
    strFile = "pannello.asp"							'il nome di questo file
    strTable = "nomi"											'nome tabella
    strKey = "ID"													'chiave primaria, contatore
    bgHeaderColor = "Orange"					
    fontHeaderColor = "black"			
    bgColor1 = "Silver"						
    fontColor1 = "Black"					
    bgColor2 = "White"						
    fontColor2 = "Black"					
    
    
    Set MyConn=Server.CreateObject("ADODB.Connection")
    MyConn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & server.MapPath("/mdb-database/database2.mdb")
    
    
    
    '**************************************
    'azioni da eseguire
    '**************************************
    Select Case Request("mode")
    	Case "AddItem"
    		AddItem
    	Case "AddItemAction"
    		AddItemAction
    	Case "EditItem"
    		EditItem
    	Case "EditItemAction"
    		EditItemAction
    	Case "DelItem"
    		delItem
    	Case Else
    		ShowAll
    End Select
    
    
    
    
    '**************************************
    'mostrare tutti i record
    'FORTEMENTE SCONSIGLIATO PER I DATABASE DI GRANDE DIMENSIONE
    '**************************************
    Sub ShowAll()
    
    	MySQL="Select * from " & strTable
    	Set MyRs=MyConn.Execute(MySQL)
    	
    	Response.write ("<h2> Tabella " & strTable & " : il contenuto</h2>")
    	Response.write ("
    
    <font size=""2"">AGGIUNGI NUOVO</font></p>")
    	Response.write ("<table border=""1"" cellpadding=""4"" cellspacing=""1"">")
    	Response.write ("<tr>")
    	
    	numerocampi=MyRs.fields.count -1
    			
    	Response.write ("<td bgcolor=""" & bgHeaderColor & """ align=""Center"" nowrap><font color=""" & fontHeaderColor & """ size=""2"">X</font></td>")
    	Response.write ("<td bgcolor=""" & bgHeaderColor & """ align=""Center"" nowrap><font color=""" & fontHeaderColor & """ size=""2"">E</font></td>")
    	
    	for i=0 to numerocampi 
    		if Not MyRs(i).name = "ID" then
    			Response.write ("<td bgcolor=""" & bgHeaderColor & """ align=""Center"" nowrap><font color=""" & fontHeaderColor & """ size=""2"">" & MyRs(i).name & "</font></td>")
    		end if
    	next 
    	
    	Response.write ("</tr>")
    	
    	do while not MyRs.eof 
    	
    	if bgColor = bgColor2 then
    		bgColor = bgColor1
    		fontColor = fontColor1
    	else
    		bgColor = bgColor2 
    		fontColor = fontColor2
    	end if
    	
    	Response.write ("<tr>")
    	Response.write ("<td align=""Center"" valign=""Top"" bgcolor=""" & bgColor & """>")
    	Response.write ("<font color=""" & fontColor & """>Elimina</font></td>")
    	Response.write ("<td align=""Center"" valign=""Top"" bgcolor=""" & bgColor & """>")
    	Response.write ("<font color=""" & fontColor & """>Modifica</font></td>")
    	
    	for i = 0 to numerocampi
    		if Not MyRs(i).name = "ID" then
    			if MyRs(i).name = "PRICE" then
    				ThisRecord = FormatCurrency(MyRs(i))
    				strAlign = "right"
    			else
    				ThisRecord = MyRs(i)
    				strAlign = ""
    			end if
    			If IsNull(ThisRecord) or ThisRecord = "" Then
    				ThisRecord = ""
    			end if 
    			ThisRecord  = Replace(ThisRecord,vbCrLf,"
    ")
    			Response.write ("<td align=""" & strAlign & """ valign=top bgcolor=""" & bgColor & """><font color=""" & fontColor & """>" & Thisrecord & "</font></td>")
    		end if
    	next 
    	
    	Response.write ("</tr>")
    	
    	MyRs.movenext
    	loop
    	
    	Response.write ("</table>")
    	
    	MyRs.close
    	Set MyRs= Nothing
    	
    end sub
    
    
    
    '**************************************
    'aggiungi
    '**************************************
    Sub AddItem()
    
    	MySQL="Select * from " & strTable
    	Set MyRs=MyConn.Execute(MySQL)
    
    	Response.write ("<h2>Aggiungi nuovo Record a " & strTable & "</h2>")
    	
    	Response.write ("<form action=""" & strFile & "?mode=AddItemAction"" method=""post"" id=form1 name=form1>")
    	Response.write ("<table>")
    	
    	numerocampi=MyRs.fields.count -1
    	
    	for i=0 to numerocampi
    	
    	if Not MyRs(i).name = "ID" then
    		ThisRecord = MyRs(i)
    		ThisRecordName = MyRs(i).name
    		If IsNull(ThisRecord) or ThisRecord = "" Then
    			ThisRecord = ""
    		end if 
    	Response.write ("<tr>")
    	Response.write ("<td align=""right"">" & ThisRecordName & ": </td>")
    	Response.write ("<td> <input name=""" & ThisRecordName & """ type=""text""></td>")
    	Response.write ("</tr>")
    	end if
    	next
    	
    	Response.write ("<tr>")
    	Response.write ("<td align=""right""><input name=""Submit"" type=submit value=""Submit""></td>")
    	Response.write ("<td><input name=""reset"" type=reset value=""Reset""></td>")
    	Response.write ("</tr>")
    	Response.write ("</table>")
    	Response.write ("</form>")
    	Response.write ("Back to list")
    	
    End Sub
    
    
    
    
    Sub AddItemAction()
    
    	MySQL="Select * from " & strTable
    	Set MyRs=MyConn.Execute(MySQL)
    
    	numerocampi=MyRs.fields.count -1
    
    	for i=0 to numerocampi
    		if Not MyRs(i).name = "ID" then
    			str = MyRs(i).name 
    			if not i = numerocampi then
    				str1 = str1 & "[" & str & "], "
    			else
    				str1 = str1 & "[" & str & "]"
    			end if
    						
    			strNames = Request(str)
    			if not i = numerocampi then
    				sqlNames1 = sqlNames1 & "'" & strNames & "', "
    			else
    				sqlNames1 = sqlNames1 & "'" &  strNames & "'"
    			end if
    		end if
    	next
    
    	MySQL1="Insert INTO " & strTable & " (" & str1 & ") VALUES (" & sqlNames1 & ")"
    	Set MyRs1=MyConn.Execute(MySQL1)
    	
    	MyConn.Close
    	set MyConn=nothing 
    	
    	Response.Redirect strFile
    
    End Sub
    
    
    
    
    '**************************************
    'modificare
    '**************************************
    Sub EditItem()
    
    	Response.write ("<h2>Modifica record nella tabella " & strTable & "</h2>")
    	
    	which=request("which")
    	
    	if isNumeric(which) then
    		MySQL="SELECT * FROM " & strTable & " Where " & strKey & " = " & which
    	else
    		MySQL="SELECT * FROM " & strTable & " Where " & strKey & " = '" & which & "'"
    	end if
    	Set MyRs=MyConn.Execute(MySQL)
    
    	Response.write ("<FORM ACTION=""" & strFile & "?mode=EditItemAction"" METHOD=POST>")
    	Response.write ("<input name=""ID"" type=""hidden"" value=""" & MyRs(strKey) & """>")
    	Response.write ("<table>")
    
    	numerocampi=MyRs.fields.count -1
    	
    	for i=0 to numerocampi
    	
    	if Not MyRs(i).name = "ID" then
    		ThisRecord = MyRs(i)
    		ThisRecordName = MyRs(i).name
    		If IsNull(ThisRecord) or ThisRecord = "" Then
    			ThisRecord = ""
    		end if 
    	Response.write ("<tr>")
    	Response.write ("<td height =""auto"" align=""right"">" & ThisRecordName & ": </td>")
    	Response.write ("<td> <input name=""" & ThisRecordName & """ type=""text"" value=""" & MyRs(i) & """></td>")
    	Response.write ("</tr>")
    	end if
    	next
    
    	Response.write ("<tr>")
    	Response.write ("<td align=""right""><INPUT NAME=""Submit"" TYPE=Submit Value=""Update""></td>")
    	Response.write ("<td><INPUT NAME=""Reset"" TYPE=Reset Value=""Reset""></td>")
    	Response.write ("</tr>")
    	Response.write ("</table>")
    	Response.write ("</FORM>")
    
    	Response.write ("Torna alla lista dei record")
    		
    	MyRs.close
    	Set MyRs= Nothing
    
    End Sub
    
    
    Sub EditItemAction()
    
    	which = Request(strKey)
    	
    	if isNumeric(which) then
    		MySQL="SELECT * FROM " & strTable & " Where " & strKey & " = " & which
    	else
    		MySQL="SELECT * FROM " & strTable & " Where " & strKey & " = '" & which & "'"
    	end if
    
    	'MySQL="Select * from " & strTable
    	Set MyRs=MyConn.Execute(MySQL)
    
    	numerocampi=MyRs.fields.count -1
    
    	for i=0 to numerocampi
    		if Not MyRs(i).name = "ID" then	
    			str = MyRs(i).name 
    			strNames = Request(str)
    			if not i = numerocampi then
    				str1 = str1 & "[" & str & "] = '" & strNames & "', "
    			else
    				str1 = str1 & "[" & str & "] = '" & strNames & "'"
    			end if
    		end if
    	next
    
    	if isNumeric(which) then
    		MySQL1="UPDATE " & strTable & " SET " & str1 & " Where " & strKey & " = " & which
    	else
            which = replace(which,"'","''")
    		MySQL1="UPDATE " & strTable & " SET " & str1 & " Where " & strKey & " = '" & which & "'"
    	end if
    
    	'MySQL1="UPDATE " & strTable & " SET " & str1 & " Where ID=" & which
    
    	Set MyRs1=MyConn.Execute(MySQL1)
    	
    	MyConn.Close
    	set MyConn=nothing
    	
    	Response.Redirect strFile
    
    End Sub
    
    
    
    
    '**************************************
    'elimina record
    '**************************************
    Sub DelItem()
    
    	which=request("which")
    	if isNumeric(which) then
    		MySQL="delete * from " & strTable & " Where " & strKey & " = " & which
    	else
    		MySQL="delete * from " & strTable & " Where " & strKey & " = '" & which & "'"
    	end if
    	
    	Set MyRs=MyConn.Execute(MySQL)
    	
    	MyConn.Close
    	set MyConn=nothing
    	
    	Response.Redirect strFile
    
    End Sub
    
    %>
    a me servirebbe appunto poter usare l'apostrofo e quando si modifica un campo avere già dentro il campo com'è al momento per modificare a seconda della necessità...

  10. #10
    Utente di HTML.it
    Registrato dal
    Oct 2006
    Messaggi
    105
    allora ho capito...almeno per il fatto del campo input che non mi presentava dinuovo il suo contenuto...
    io ho bisogno che questo database contenga nei record testi abbastanza lunghi...
    quindi se cambio i tipi di dati in memo nel database originale...
    non mi viene + mostrato il contenuto del campo nella fase di modifica...
    mi spiegate il perchè??? così almeno inizio a risolvere il primo problema

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 © 2026 vBulletin Solutions, Inc. All rights reserved.