Articles → ADO.NET → Datareader In Ado.Net
Datareader In Ado.Net
Purpose
Example
using System;
using System.Data.SqlClient;
namespace ReaderDemo
{
class Program
{
static void Main(string[] args)
{
string connectionString = @"[connection_string]";
string query = "select * from Courses";
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
using (SqlCommand command = new SqlCommand(query, connection))
{
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(reader["course_name"]);
}
}
}
Console.ReadLine();
}
}
}
Output