---
title: "Proof of Disconnected Data Access in ADO.NET"  
description: "disconnected data access means fetching data from a database, working with it in-memory (using DataSet, DataTable, or DataView), and not maintaining a"  
author: "ICSM Computer"  
published: 2025-02-12  
updated: 2025-02-12  
canonical: https://www.mindstick.com/blog/305249/proof-of-disconnected-data-access-in-ado-dot-net  
category: "ado.net"  
tags: ["c#", "ado.net"]  
reading_time: 2 minutes  

---

# Proof of Disconnected Data Access in ADO.NET

In [ADO.NET](https://www.mindstick.com/articles/804/connection-pooling-in-ado-dot-net), **[disconnected](https://www.mindstick.com/blog/300962/how-modern-life-disconnected-from-nature) [data access](https://www.mindstick.com/blog/301551/risks-and-challenges-of-data-access-and-sharing)** means fetching data from a database, working with it in-memory (using `DataSet`, `DataTable`, or `DataView`), and not maintaining an active connection to the database.

`DataView` operates on a `DataTable`, which is disconnected from the database once data is retrieved. Below is a demonstration proving that `DataView` works **without a continuous [database connection](https://www.mindstick.com/forum/159617/how-to-connect-to-a-database-connection-in-java)**.

####

#### Fetch Data from Database (Open Connection Only Once)

```cs
using System;
using System.Data;
using System.Data.SqlClient;

class Program
{
    static void Main()
    {
        // Connection string (Modify based on your database)
        string connectionString = "Server=your_server;Database=your_db;Integrated Security=True;";

        // Disconnected data access: Fetch data once, then close connection
        DataTable dt = new DataTable();

        using (SqlConnection conn = new SqlConnection(connectionString))
        {
            conn.Open();
            string query = "SELECT ID, Name, Age FROM Employees";  // Fetch data from DB
            SqlDataAdapter adapter = new SqlDataAdapter(query, conn);
            adapter.Fill(dt);  // Data loaded into DataTable (Disconnected)
            conn.Close();  // Connection is now closed
        }

        // 💡 Proof: Data is stored in-memory. We no longer need the database connection.
        Console.WriteLine("Database Connection is Closed!");
        Console.WriteLine($"Total Rows Retrieved: {dt.Rows.Count}");

        // Creating DataView from DataTable
        DataView dv = new DataView(dt);

        // Apply Sorting
        dv.Sort = "Age ASC";

        // Apply Filtering (Only employees older than 25)
        dv.RowFilter = "Age > 25";

        // Display Data (Working without DB connection)
        Console.WriteLine("\nFiltered Employees (Age > 25):");
        foreach (DataRowView row in dv)
        {
            Console.WriteLine($"ID: {row["ID"]}, Name: {row["Name"]}, Age: {row["Age"]}");
        }

        // Proving disconnection: Modify DataView without any DB connection
        DataRowView newRow = dv.AddNew();
        newRow["ID"] = 999;
        newRow["Name"] = "John Doe";
        newRow["Age"] = 35;
        newRow.EndEdit();

        Console.WriteLine("\nNew Row Added (Without DB Connection):");
        foreach (DataRowView row in dv)
        {
            Console.WriteLine($"ID: {row["ID"]}, Name: {row["Name"]}, Age: {row["Age"]}");
        }
    }
}
```

### Proof of Disconnected Access

1. **Database connection is opened only once** to [fetch data](https://www.mindstick.com/forum/160510/how-to-fetch-data-from-the-database-in-the-dot-net-console-application-using-c-sharp).
2. **Data is stored in** `DataTable` (in-memory [storage](https://www.mindstick.com/articles/44536/finding-your-self-storage-facility)).
3. `DataView` **operates independently** without requiring a live database connection.
4. **[Sorting](https://www.mindstick.com/articles/1581/sorting-list-with-side-bar), filtering, and adding new rows happen without re-querying the database**.

---

Original Source: https://www.mindstick.com/blog/305249/proof-of-disconnected-data-access-in-ado-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
