ITP

BSc IT - Web Application Development - ASP.NET

Explain Data reader object and use.

In : BSc IT Subject : Web Application Development - ASP.NET

A Data Reader is a fast, read-only, forward-only stream of data from a database. 

Use:

  • Retrieves data quickly and efficiently when you only need to read it once (e.g., displaying data in a list).
  • Connected architecture: works while the connection to the database is open.

Example :

using (SqlConnection conn = new SqlConnection("your_connection_string")) {
    SqlCommand cmd = new SqlCommand("SELECT * FROM Customers", conn);
    conn.Open();
    SqlDataReader reader = cmd.ExecuteReader();
    
    while (reader.Read()) {
        Console.WriteLine(reader["CustomerName"]);
    }
}

About us

A truly open platform where you may ask questions and get answers. We also provide comprehensive and easy-to-understand answers to question papers.  discover...

Site status

Flag Counter

Privacy Policy

Sitemap