Visualizzazione dei risultati da 1 a 5 su 5

Discussione: readonly + reader

  1. #1
    Utente di HTML.it L'avatar di Francis87
    Registrato dal
    Jun 2003
    Messaggi
    5,970

    readonly + reader

    1. come posso impostare il valore Readonly a dei Textbox nel codice VB.net, quindi non intervenendo sul tag?

    2. ho questo codice:
    codice:
     Dim sqlString = "SELECT * FROM utenti WHERE [password] ='" & password & "' AND username='" & username & "'"
     Dim myCommand As New OleDbCommand(sqlString, Con) 
     Dim objReader As oleDbDataReader
     Con.Open()
     objReader = myCommand.ExecuteReader()
     If Not objReader.Read() Then
      lblError.Text = "Errore nel login."
      objReader.Close()
      Con.Close()
      Exit Sub
     Else
      Session.Item("login") = 1
      Session.Item("username") = username
      'Session.Item("mail") = campo email
      'se campo isAdmin è 1 Then
      'Session.Item("admin") = 1 
      Response.Redirect("http://www.noidellac.it/dotnetguestbook.aspx")
     End If
    come posso ricavare i valori dei campi del record corrente?
    grazie mille!

    Heaven's closed. Hell sold out.

    Linux 2.6.26-2-amd64
    Debian squeeze

  2. #2
    Utente di HTML.it
    Registrato dal
    Aug 2001
    Messaggi
    1,482

    Re: readonly + reader

    1
    codice:
    TuoTextBox.ReadOnly = True
    2
    codice:
     Dim sqlString = "SELECT * FROM utenti WHERE [password] ='" & password & "' AND username='" & username & "'"
     Dim myCommand As New OleDbCommand(sqlString, Con) 
     Dim objReader As oleDbDataReader
     Con.Open()
     objReader = myCommand.ExecuteReader()
     If Not objReader.HasRows Then
      lblError.Text = "Errore nel login."
      objReader.Close()
      Con.Close()
      Exit Sub
     Else
      Session.Item("login") = 1
      Session.Item("username") = username
      Session.Item("mail") = objReader("NomeCampoEmail")
      If ObjReader("isAdmin") = 1 Then
        Session.Item("admin") = 1 
      End If
      Response.Redirect("http://www.noidellac.it/dotnetguestbook.aspx")
     End If
    Per verificare l'esistenza di record in un oggetto reader ti consiglio di usare la prop. HasRows al posto del metodo Read, perchè quest'ultimo ogni volta che viene invocato avanza di una posizione.
    La prop HasRows è utilizzabile dalla versione 1.1 in poi del framework.

    Hey hey, my my Rock and roll can never die!

  3. #3
    Utente di HTML.it L'avatar di Francis87
    Registrato dal
    Jun 2003
    Messaggi
    5,970
    No data exists for the row/column.
    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.InvalidOperationException: No data exists for the row/column.

    Source Error:


    Line 154: Session.Item("login") = 1
    Line 155: Session.Item("username") = username
    Line 156: Session.Item("mail") = objReader("mail")
    Line 157: If ObjReader("isAdmin") = 1 Then
    Line 158: Session.Item("admin") = 1

    versione 1.1.43ecc ecc
    Heaven's closed. Hell sold out.

    Linux 2.6.26-2-amd64
    Debian squeeze

  4. #4
    Utente di HTML.it
    Registrato dal
    Aug 2001
    Messaggi
    1,482

    Re: Re: readonly + reader

    codice:
     Dim sqlString = "SELECT * FROM utenti WHERE [password] ='" & password & "' AND username='" & username & "'"
     Dim myCommand As New OleDbCommand(sqlString, Con) 
     Dim objReader As oleDbDataReader
     Con.Open()
     objReader = myCommand.ExecuteReader()
     If Not objReader.HasRows Then
      lblError.Text = "Errore nel login."
      objReader.Close()
      Con.Close()
      Exit Sub
     Else
      While objReader.Read()
        Session.Item("login") = 1
        Session.Item("username") = username
        Session.Item("mail") = objReader("NomeCampoEmail")
        If ObjReader("isAdmin") = 1 Then
          Session.Item("admin") = 1 
        End If
        Response.Redirect("http://www.noidellac.it/dotnetguestbook.aspx")
      End While 
     End If

    Hey hey, my my Rock and roll can never die!

  5. #5
    Utente di HTML.it L'avatar di Francis87
    Registrato dal
    Jun 2003
    Messaggi
    5,970
    grazie!

    sono proprio fagiano!
    Heaven's closed. Hell sold out.

    Linux 2.6.26-2-amd64
    Debian squeeze

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.