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

    errore su select semplice semplice

    allora questo è il mio code...
    codice:
        Private Sub Check(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim sql As New MySqlCommand("Select * from utenti WHERE username = '" & username.Text & "' ", myConnection)
            Dim qq As MySqlDataReader
            qq = sql.ExecuteScalar
            Response.Write(username.Text)
            If username.Text = qq("username") Then
                Response.Write("HAI RAGIONE")
            Else
                Response.Write("asd")
            End If
            myConnection.Close()     
        End Sub
    questo l'errore

    Object reference not set to an instance of an object.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:


    Line 14: qq = sql.ExecuteScalar
    Line 15: Response.Write(username.Text)
    Line 16: If username.Text = qq("username") Then
    Line 17: Response.Write("HAI RAGIONE")
    Line 18: Else


    Ho letto che per estrarre un record solo non server fare sql.ExecuteReader, ma basta un ExecuteScalar

    sembra però che nn funzioni con entrambi
    sapete dirmi dove sbaglio?
    grazie 1000
    -------------------------
    ..::`DrUmM\n0`::..
    www.jonathandomenici.com

  2. #2
    Utente di HTML.it L'avatar di cassano
    Registrato dal
    Aug 2004
    Messaggi
    3,002
    la connessione è apera ????

  3. #3
    certo
    -------------------------
    ..::`DrUmM\n0`::..
    www.jonathandomenici.com

  4. #4
    Ma ci sono dati per la username selezionata?
    Controlla che esiste l'oggetto Reader quando cerchi di usarlo.

  5. #5
    ExecuteScalar, lo dice la parola, estrae uno scalare e quindi un singolo valore e non un record.

    Utilizza ExecuteReader. Per poi trovare il valore

    While qq.Read
    If username.Text = qq("username") Then
    Response.Write("HAI RAGIONE")
    Else
    Response.Write("asd")
    End If
    End While

    Fammi sapere
    Ciao
    K
    Kalman

  6. #6
    si infatti avevo intuito...
    ora questo problema è risolto
    grazie a tutti.
    -------------------------
    ..::`DrUmM\n0`::..
    www.jonathandomenici.com

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.