Pagina 1 di 3 1 2 3 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 24

Discussione: Update multiplo...

  1. #1

    Update multiplo...

    Ciao a tutti.
    Devo fare la seguente cosa.

    Ho 2 variabili X e Y che assumono a loro volta un nome diverso in base al numero assunto dalla variabile n .

    n è un numero compreso tra 1 e 9
    mettimo che n=3
    avro' X1 Y1 X2 Y2 X3 Y3

    il mio problema è che devo fare un update dei campi X e Y nel mio db con i valori Xn Yn ovvero modificare tanti record X Y in funzione al numero assunto da n.


    Ho fatto una cosa di questo tipo usando for ma non funza...
    codice:
    sql = "UPDATE layout set stato='"&True&"', UserID='"&ID&"' " 
    for i = 1 to n
    sql = sql & "WHERE X=" & X(i) & " AND Y=" & Y(i)
    next
    [The goal is soul]

  2. #2
    ci credo che non funzia hai messo il where nel for...

    codice:
    sql = "UPDATE layout set stato='"&True&"', UserID='"&ID&"' WHERE" 
    for i = 1 to n
    if i>1 then sql=sql & " or"
    sql = sql & " (X=" & X(i) & " AND Y=" & Y(i) & ")"
    next
    
    response.write sql
    response.end
    guarda se è così che deve venire la query perchè immagino che nel database x e y per lo stesso userid assumano diversi valori


  3. #3
    sempre errore

    Microsoft VBScript runtime error '800a000d'

    Type mismatch: 'X'

    alla riga sql = sql & " (X=" & X(i) & " AND Y=" & Y(i) & ")"
    [The goal is soul]

  4. #4
    nessuno puo' darmi 1 aiutino?
    [The goal is soul]

  5. #5
    mi fai un esempi concreto di come deve venire la query perchè mi sa che hai le idee un pò confuse.... ad ES: ma X e Y sono due array oppure la (i) ce l'hai messa per bellezza?

  6. #6
    lo so che sn un po' confuso...

    allora X e Y sono i campi da aggiornare nel db
    mentre
    questi sono i valori da inserire in X e Y(non è detto che ci siano tutti ovviamente, in base al numero assunto da n c saranno Xn e Yn)

    X1=request.querystring("X1")
    X2=request.querystring("X2")
    X3=request.querystring("X3")
    X4=request.querystring("X4")
    X5=request.querystring("X5")
    X6=request.querystring("X6")
    X7=request.querystring("X7")
    X8=request.querystring("X8")
    X9=request.querystring("X9")
    Y1=request.querystring("Y1")
    Y2=request.querystring("Y2")
    Y3=request.querystring("Y3")
    Y4=request.querystring("Y4")
    Y5=request.querystring("Y5")
    Y6=request.querystring("Y6")
    Y7=request.querystring("Y7")
    Y8=request.querystring("Y8")
    Y9=request.querystring("Y9")

    L'sql dovrebbe essere
    codice:
    UPDATE layout SET stato=True AND USERID=ID WHERE X='Xn' AND Y='Yn'
    dove Xn e Yn sono le righe da modificare dei campi X e Y

    Esempio:
    n=2
    USERID=Paolo
    X1=A
    Y1=2

    X2=B
    Y2=4

    la query deve aggiornarmi del db cosi'
    codice:
    USERID     X   Y   stato
    --------------------------
    Paolo      A   2   True
    Paolo      B   4   True
    [The goal is soul]

  7. #7
    VVoVe:

    codice:
    dim X(9),Y(9)
    
    for i=0 to 8
    X(i)=request.form("X" & (i+1) )
    Y(i)=request.form("Y" & (i+1) )
    next
    
    sql = "UPDATE layout set stato='true', UserID='"&ID&"' WHERE" 
    for i = 0 to ubound(X)
    if i>0 then sql=sql & " or"
    sql = sql & " (X=" & X(i) & " AND Y=" & Y(i) & ")"
    next
    
    response.write sql
    response.end
    dovrebbe tirarti fuori una query fatta così:
    codice:
    UPDATE layout set stato='true',UserID='xxx' where (X=A and Y=A1) or (X=B and Y=B1) etc etc

  8. #8
    codice:
    dim X(9),Y(9)
    
    for i=0 to 8
    X(i)=request.form("X" & (i+1) )
    Y(i)=request.form("Y" & (i+1) )
    next
    
    sql = "UPDATE layout set stato='true', UserID='"&ID&"' WHERE" 
    for i = 0 to ubound(X)
    if len(trim(X(i)))>0 then
    if i>0 then sql=sql & " or"
    sql = sql & " (X=" & X(i) & " AND Y=" & Y(i) & ")"
    end if
    next
    
    response.write sql
    response.end

  9. #9
    Sembra perfetto adesso..

    la query è OK

    codice:
    UPDATE layout set stato='true', UserID='353057486' WHERE (X=F AND Y=15) or (X=F AND Y=17) or (X=F AND Y=19)
    ma mi da errore se eseguo la query proprio alla riga Conn.Execute(sql)

    Microsoft OLE DB Provider for ODBC Drivers (0x80040E10)
    [Microsoft][Driver ODBC Microsoft Access] Parametri insufficienti. Previsto 1.

    Grazie ancora dell'aiuto!
    [The goal is soul]

  10. #10
    scusa ma sei sicuro che lo "USERID" debba essere UPDATO? non è che va nella condizione di WHERE?


    ovvero devi aggiornare stato=true per l'utente che hai id=userID e X=aa e Y=bb?

    se così fosse la query andrebbe riscritta così:

    codice:
    dim X(9),Y(9)
    
    for i=0 to 8
    X(i)=request.form("X" & (i+1) )
    Y(i)=request.form("Y" & (i+1) )
    next
    dim vuoto: vuoto=0
    sql = "UPDATE layout set stato='true' WHERE UserID='"&ID&"' and (" 
    for i = 0 to ubound(X)
    if len(trim(X(i)))>0 then
    if vuoto>0 then sql=sql & " or"
    sql = sql & " (X=" & X(i) & " AND Y=" & Y(i) & ")"
    vuoto=vuoto+1
    end if
    next
    sql=sql & ")"

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.