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

    leggere e modificare i dati all'interno di una tabella su database Access su texarea

    Allora ecco il mio problema:
    Con il seguente codice che posto apro tutti i campi record presenti all'interno di una tabella su database access, ed ogi singolo campo si trova all'interno di una textarea propria:

    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 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
    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


    Il problema è il seguente:

    Se trasformo uno dei campi della tabella in campo "Memo" invece che campo "Testo" i dati non me li stampa + a video perchè dov'è l'errore?

  2. #2
    copia e incolla, to'

    ----------------------------------------------------
    nel caso specifico, la ragione sta nel fatto che il campo memo
    (in ogni db, non solo access) non rientra nelle categorie standard:
    non è una stringa, non è un numero, non è una data.
    aggiungendo & "" si forza ASP a costringerlo dentro una stringa.
    probabilmente anche CStr(campo) sarebbe andato bene.
    a volte (mi sembra di ricordare lo faccia di più con mySQL)
    questi trucchi non funzionano se hai letto il campo con
    SELECT * FROM Tabella.
    Se usi
    SELECT elenco campi FROM tabella (cioè elenchi i campi uno per uno)
    funzia. Qui forse è un'esasperazione del concetto di cui sopra.
    In più, con sql2005/varchar(max) il campo 'memo' deve essere l'ultimo della select
    (non riesco qui a capire il perchè...)
    ----------------------------------------------------

  3. #3

    Re optime

    No il campo lo leggo cosi
    Codice:

    <%
    strFile = "file.asp" 'il nome del file dove girano i comandi dello script (stampa a video)
    strTable = "risultati" '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("database.mdb")

    segue codice.......
    %>


    Cosa mi consigliate di fare o provare?
    Ad esempio il campo "text" all'interno dello script, limita in qualche modo la lettura dei dati ? Ho provato a modificare i campi con "texarea" ma il risultato non cambia.

    Lo script merita!!!
    Tutte le funzioni per manipolare una tabella su di un'unico file, grande!!!

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.