Visualizzazione dei risultati da 1 a 8 su 8
  1. #1
    Utente di HTML.it
    Registrato dal
    Apr 2003
    Messaggi
    327

    [VB6]Strano problema con INSERT INTO

    Ciao a tutti. vi riport il sorgente, ho uno strano problema con la INSERT INTO.

    codice:
     If txt_username.Text <> "" And txt_pass.Text <> "" And txt_ripass.Text <> "" And txt_nome.Text <> "" And txt_cogn.Text <> "" And txt_conto.Text <> "" And txt_saldo.Text <> "" Then
      If txt_pass.Text = txt_ripass.Text Then
       If IsNumeric(txt_conto.Text) And IsNumeric(txt_saldo.Text) Then
         Set cn = New ADODB.Connection
         Set rs = New ADODB.Recordset
         cn.CursorLocation = adUseClient
         cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database\conto_corrente.mdb;Persist Security Info=False"
         sql = "INSERT INTO utenti (username, password) VALUES ('" & txt_username.Text & "', '" & txt_pass.Text & "')"
         Set rs = cn.Execute(sql)
         id_utente = rs(id_utente).value
        ElseIf IsNumeric(txt_conto.Text) = False Then
         MsgBox "Numero di conto non valido", vbOKOnly + vbExclamation + vbDefaultButton1, "Errore"
        Else
         MsgBox "Importo non valido", vbOKOnly + vbExclamation + vbDefaultButton1, "Errore"
       End If
       Else
        MsgBox "Le password inserite sono diverse", vbOKOnly + vbExclamation + vbDefaultButton1, "Errore"
        txt_pass.Text = ""
        txt_ripass.Text = ""
       End If
      Else
       MsgBox "Compilare tutti i campi", vbOKOnly + vbExclamation + vbDefaultButton1, "Errore"
     End If
    L'errore è che la sintassi INSERT INTO è errata. Allora sono andato in debug ho visto il contenuto della sql ed è questo: "INSERT INTO utenti (username,password) VALUES ('miciomicio', 'baobao')"
    Ho preso il contenuto sono andato in access ho fatto una query con quella insert into e mi funziona!!
    Sempre nello stesso programma ho usato la insert into e mi funziona senza problemi.
    Dove sbaglio?

    Grazie
    By Games

  2. #2
    La parola "password" è una parola riservata, pertanto cambia il nome del campo password in un altro a tuo piacimento p.es. "pass"

  3. #3
    Utente di HTML.it
    Registrato dal
    Apr 2003
    Messaggi
    327
    Non riesco veramente a capire, ho fatto una insert into sotto e tutto funziona correttamente.


    codice:
     If txt_username.Text <> "" And txt_pass.Text <> "" And txt_ripass.Text <> "" And txt_nome.Text <> "" And txt_cogn.Text <> "" And txt_conto.Text <> "" And txt_saldo.Text <> "" Then
      If txt_pass.Text = txt_ripass.Text Then
       If IsNumeric(txt_conto.Text) And IsNumeric(txt_saldo.Text) Then
         Set cn = New ADODB.Connection
         Set rs = New ADODB.Recordset
         cn.CursorLocation = adUseClient
         cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Database\conto_corrente.mdb;Persist Security Info=False"
         Rem sql = "INSERT INTO utenti (username, password) VALUES ('entrata', 'miao')"
         Rem cn.Execute (sql)
         Rem id_utente = rs(id_utente).value
         sql = "INSERT INTO conto_corrente (id_conto, nome, cognome, banca, saldo, id_utente) VALUES ('" & txt_conto.Text & "', '" & txt_nome.Text & "', '" & txt_cogn.Text & "' , '" & txt_banca.Text & "', '" & txt_saldo.Text & "', '1')"
         cn.Execute (sql)
        ElseIf IsNumeric(txt_conto.Text) = False Then
         MsgBox "Numero di conto non valido", vbOKOnly + vbExclamation + vbDefaultButton1, "Errore"
        Else
         MsgBox "Importo non valido", vbOKOnly + vbExclamation + vbDefaultButton1, "Errore"
       End If
       Else
        MsgBox "Le password inserite sono diverse", vbOKOnly + vbExclamation + vbDefaultButton1, "Errore"
        txt_pass.Text = ""
        txt_ripass.Text = ""
       End If
      Else
       MsgBox "Compilare tutti i campi", vbOKOnly + vbExclamation + vbDefaultButton1, "Errore"
     End If
    Perchè la insert into la tabella utenti non funziona'? L'ho scritta allo stesso modo.

    La tabella utenti è così composta:
    id_utente ( contatore chiave principale)
    username
    password
    By Games

  4. #4
    Utente di HTML.it
    Registrato dal
    Apr 2003
    Messaggi
    327
    Funziona!

    Grazie
    By Games

  5. #5

  6. #6
    Utente di HTML.it
    Registrato dal
    Apr 2003
    Messaggi
    327
    C'è un modo per trovare il valore della chiave principale subito dopo la insert?
    O devo fare una select?
    By Games

  7. #7
    C'è un modo per trovare il valore della chiave principale subito dopo la insert?
    O devo fare una select?
    Devi fare una SELECT.

  8. #8
    Utente di HTML.it
    Registrato dal
    Apr 2003
    Messaggi
    327
    Thanks
    By Games

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.