Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Cynthia SathuragiriRank #937 · 2.2K reputationPosted Sep 12, 2025, 3:53 AM EDT
DataTable → Stores the whole table in memory, you can use it later even without a database connection.
DataReader → Reads data one row at a time, very fast, but needs the database connection to stay open.
Sangeetha SRank #212 · 11.4K reputationPosted Sep 15, 2025, 12:29 AM EDT
A DataReader provides a fast, read-only, and forward-only stream of data from a database. It's connected to the data source and processes one row at a time, making it highly efficient and low on memory usage.
In contrast, a DataTable is a disconnected, in-memory representation of a single database table. It holds all the data at once, allowing for powerful features like searching, filtering, sorting, and navigating data in any direction. However, this comes with a greater memory footprint.
Sandhiya PriyaRank #26 · 43.2K reputationPosted Oct 13, 2025, 3:06 AM EDT
Difference Between
DataTableandDataReaderin C#Both
DataTableandDataReaderare used to work with data from a database in ADO.NET, but they have key differences:DataTableDataReaderSqlDataAdapter.Fill(DataTable)SqlCommand.ExecuteReader()Example of DataReader
using(SqlConnection con = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand("SELECT * FROM Students", con); con.Open(); SqlDataReader reader = cmd.ExecuteReader(); while(reader.Read()) { Console.WriteLine(reader["Name"] + " - " + reader["Age"]); } reader.Close(); }Forward-only, faster, requires open connection.
Example of DataTable
using(SqlConnection con = new SqlConnection(connectionString)) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Students", con); DataTable dt = new DataTable(); da.Fill(dt); foreach(DataRow row in dt.Rows) { Console.WriteLine(row["Name"] + " - " + row["Age"]); } }Random access, can manipulate data, disconnected from DB after fill.
Summary
Use DataReader for fast, read-only, forward-only access.
Use DataTable when you need disconnected, manipulable, or bindable data.