Visualizzazione dei risultati da 1 a 2 su 2

Discussione: [C#] lettura recordset

  1. #1

    [C#] lettura recordset

    Ciao a tutti e scusate se scrivo castronerie ma sono novello di c# e .net

    vi posto un codice che penso serva a leggere un recordset di una tabella...
    ma a quanto pare nn va...

    io dovrei leggere un recordset (quello che nel vecchio asp era... rs("campo_tabella")

    come posso fare ?

    grazie mille

    Codice PHP:
       sql2 "SELECT * FROM utenti WHERE email = " email;
       
    MySqlCommand rs = new MySqlCommand(sql2connection);
       
    rs.CommandText sql2;
       try
       {
           
    rs.ExecuteReader();
       }
       catch (
    Exception ex2)
       {
           
    Response.Write(ex2.ToString());
       }
        finally
       {
           
    connection.Close();
       }
       
    //Response.Write("TUTT OK"); 
    grazie di nuovo
    -------------------------
    ..::`DrUmM\n0`::..
    www.jonathandomenici.com

  2. #2
    Utente di HTML.it L'avatar di pietro09
    Registrato dal
    Jan 2002
    Messaggi
    10,116
    Ho una pagina di esempio che avevo chiamato "iterare_datareader.aspx"

    Nella pagina ho una label chiamata Label1

    Il codice è (è in Basic, ma non avrai difficoltà a tradurlo in c# )

    codice:
    Option Strict On
    
    Partial Class CorsoApogeo_wrox_gestione_dati_datareader_iterare_datareader
        Inherits System.Web.UI.Page
    
    
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim sql$ = "SELECT * FROM CAMPI"
    
            Dim Reader As OleDbDataReader = Nothing
            Dim s As New StringBuilder
    
            Try
                Reader = GetDataReader(StringaConnessioneTest, sql)
    
                Dim Colonne% = Reader.FieldCount
                s.Append("<table border='1' cellspacing='1' cellpadding='2'>")
                s.Append("<tr>")
    
                For j As Integer = 0 To Colonne - 1
                    s.Append("<th>" & Reader.GetName(j) & "</th>")
                Next
                s.Append("<th>" & "link" & "</th>")
                s.Append("</tr>")
    
                Do While (Reader.Read)
                    s.Append("<tr>")
                    For j As Integer = 0 To Colonne - 1
                        s.Append("<td>" & libreria.NullToSpace(Reader.Item(j)) & "</td>")
                    Next
                    s.Append("<td>" & "link" & "</td>")
                    s.Append("</tr>")
    
                Loop
    
                Me.Label1.Text = s.ToString
    
    
    
    
            Catch er As Exception
                Me.Label1.Text = er.Message
    
            Finally
                If Reader IsNot Nothing Then Reader.Close()
    
            End Try
    
        End Sub
    
    End Class

    ps. dimenticavo
    GetDataReader è una funzione di libreria esterna compilata
    codice:
        Public Function GetDataReader(ByVal stringaConnessione$, ByVal stringaSQL$) As OleDbDataReader
            Dim Reader As OleDbDataReader
            Dim Connessione As OleDbConnection
            Try
                Connessione = New OleDbConnection(stringaConnessione)
                Connessione.Open()
                Dim Comando As New OleDbCommand(stringaSQL, Connessione)
                Reader = Comando.ExecuteReader(CommandBehavior.CloseConnection)
                Return Reader
            Catch Errore As Exception
                Connessione.Close()
                Throw
            End Try
    
    
        End Function
    Pietro

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.