Roadmap › ADO.NET — Connected & Disconnected Data Access › Module: Disconnected Architecture
Lessons in this course (9)

5. DataSet, DataTable and DataAdapter

IntermediateMediumLesson 5 of 9
csharp
var ds = new DataSet();
using var da = new SqlDataAdapter("SELECT Id, Name, Price FROM Products", cs);
da.Fill(ds, "Products");                  // opens + closes connection automatically

DataTable t = ds.Tables["Products"]!;
foreach (DataRow row in t.Rows) Console.WriteLine($"{row["Name"]}: {row["Price"]}");

t.Rows[0]["Price"] = 999m;                // RowState = Modified
var cb = new SqlCommandBuilder(da);       // auto-generates INSERT/UPDATE/DELETE (needs a primary key)
da.Update(ds, "Products");                // pushes changes back

DataView view = new(t) { RowFilter = "Price > 1000", Sort = "Price DESC" };
DataReaderDataSet
Connected, forward-only, read-onlyDisconnected, in-memory, random access, editable
Very fast, low memoryHeavier; holds all rows
One row at a timeMultiple tables + relations + constraints
Best for APIs, reports streamingLegacy WinForms grids, offline editing, XML serialisation

Modern apps rarely use DataSets; they map to POCOs with Dapper/EF.