ScholarQuill logoScholarQuillUniversity Notes
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
Study Tools
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
Contact
ScholarQuill logo
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
ScholarQuill logoScholarQuillUniversity Notes
Study PortalEC-332Adonet Disconnected Mo…
Ctrl + K
Login
Explore
Search
Semester
Papers
CGPA
    EC-332

    Enterprise Application Development

    Progress0 / 37 done
    Topics37
    1Microsoft technology history2Introduction to .NET and its architecture3Concept of MSIL, CLR, CLS, CTS
    4Managed and Unmanaged Code5.Net Assembly6Introduction to C# fundamentals7Boxing and Unboxing8Implementing multi-tier architecture
    9SQL Injection, parameterized queries10Usage of data set, Data adapter and command builder in disconnected model
    11Multicast delegates12Introduction to windows forms13HTML
    14javascript and its data types, variables, functions15Debugging javascript using Firebug
    16Browser's Object (BOM), Document Object Model
    17Jquery effects
    18LINQ to Objects, LINQ to SQL19Query syntax, Operations (projection, filtering and join) using Linq Queries
    20The entity data model, CSDL21Eager vs lazy loading, POCO classes, DBContext API22Querying entity data models23Introduction to ASP.NET MVC24MVC application structure, Controllers overview25Action Methods, Parameterized action methods26Introduction to razor syntax27Code expressions, Code Blocks, Implicit Vs Explicit Code Expression28Data annotations, Client and Server Side Validation29Validation and model binding, Validation and model state30MVC Membership, Authorization and security
    31SOAP, WSDL32Service contract, Data contract, XML, WCF bindings33ABC of WCF, Restful services34Consuming rest services (CRUD operations) using Jquery AJAX and JSON35Introduction to web API36Example of web API using CRUD Example37MVC routing
    6 min read
    Topic 10 of 37
    Topic Study Note Illustration
    10

    Usage of data set, Data adapter and command builder in disconnected model

    In ADO.NET, the disconnected model allows for more flexible data management by enabling the application to interact with the database without maintaining an active connection to the...

    In ADO.NET, the disconnected model allows for more flexible data management by enabling the application to interact with the database without maintaining an active connection to the data source. The DataSet, DataAdapter, and CommandBuilder are key components used in this disconnected model.

    1. DataSet

    The DataSet is an in-memory representation of data that can hold multiple tables and their relationships. It is disconnected from the database, meaning it doesn't require an open connection to the data source to manipulate data. A DataSet can be populated by a DataAdapter and later updated to the database.

    • Key Features:
      • Holds data in memory in the form of DataTable objects.
      • Can maintain relationships between tables, making it useful for complex data manipulations.
      • Supports data binding, allowing data to be easily bound to UI controls.
      • Enables offline manipulation of data (i.e., you can modify data, and later update the database).

    Example of using DataSet:

    using System;
    using System.Data;
    using System.Data.SqlClient;
    
    class Program
    {
        static void Main()
        {
            // Define connection string
            string connectionString = "your_connection_string_here";
            
            // Create a connection to the database
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                // Create DataAdapter to fetch data
                string query = "SELECT * FROM Employees";
                SqlDataAdapter dataAdapter = new SqlDataAdapter(query, connection);
                
                // Create DataSet to hold data
                DataSet dataSet = new DataSet();
                
                // Fill the DataSet with data from the database
                dataAdapter.Fill(dataSet, "Employees");
                
                // Work with the data in the DataSet
                foreach (DataRow row in dataSet.Tables["Employees"].Rows)
                {
                    Console.WriteLine($"{row["EmployeeID"]} - {row["Name"]}");
                }
            }
        }
    }
    
    • In this example, a DataSet is used to load data from the Employees table. It can be used to display data in the UI or perform manipulations like sorting, filtering, or editing.

    2. DataAdapter

    The DataAdapter is used to bridge the gap between the disconnected DataSet and the database. It is responsible for fetching data from the database and filling the DataSet, and also for updating the database with changes made to the DataSet.

    • Key Features:
      • Fill: Used to load data from the database into a DataSet.
      • Update: Used to propagate changes made in the DataSet back to the database.
      • Works with SQL commands (e.g., SELECT, INSERT, UPDATE, DELETE) to retrieve or modify data.

    Example of using DataAdapter:

    using System;
    using System.Data;
    using System.Data.SqlClient;
    
    class Program
    {
        static void Main()
        {
            string connectionString = "your_connection_string_here";
            string query = "SELECT * FROM Employees";
    
            // Create connection and DataAdapter
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlDataAdapter dataAdapter = new SqlDataAdapter(query, connection);
    
                // Create DataSet
                DataSet dataSet = new DataSet();
    
                // Fill DataSet with data
                dataAdapter.Fill(dataSet, "Employees");
    
                // Modify the data in the DataSet (Example: Update employee name)
                DataRow row = dataSet.Tables["Employees"].Rows[0];
                row["Name"] = "Updated Employee Name";
    
                // Set up the update command for the DataAdapter
                SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
    
                // Update the database with changes made to the DataSet
                dataAdapter.Update(dataSet, "Employees");
            }
        }
    }
    
    • In this example, a DataAdapter is used to fetch data from the Employees table and load it into a DataSet. After making changes to the DataSet (like modifying an employee's name), the Update method is used to push those changes back to the database.

    3. CommandBuilder

    The CommandBuilder is a helper class used to automatically generate SQL commands for Insert, Update, and Delete operations. It works with a DataAdapter to generate the necessary SQL statements when updating a DataSet. This helps simplify the process of creating commands for operations based on the DataSet schema.

    • Key Features:
      • Automatically generates SQL commands for CRUD operations.
      • Useful when working with a DataAdapter in a disconnected environment.
      • Reduces the need to manually write SQL for each operation.

    Example of using CommandBuilder:

    using System;
    using System.Data;
    using System.Data.SqlClient;
    
    class Program
    {
        static void Main()
        {
            string connectionString = "your_connection_string_here";
            string query = "SELECT * FROM Employees";
    
            // Create connection and DataAdapter
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlDataAdapter dataAdapter = new SqlDataAdapter(query, connection);
    
                // Create CommandBuilder
                SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
    
                // Create DataSet
                DataSet dataSet = new DataSet();
    
                // Fill DataSet with data
                dataAdapter.Fill(dataSet, "Employees");
    
                // Modify data in the DataSet
                DataRow row = dataSet.Tables["Employees"].Rows[0];
                row["Name"] = "New Employee Name";
    
                // Update the database with changes
                dataAdapter.Update(dataSet, "Employees");
    
                Console.WriteLine("Database updated successfully.");
            }
        }
    }
    
    • In this example, the SqlCommandBuilder automatically generates the INSERT, UPDATE, and DELETE SQL commands for the DataAdapter based on the Employees table schema. The DataAdapter then uses these commands to push changes from the DataSet back to the database.

    How They Work Together

    1. DataAdapter: Fills the DataSet with data by executing a SELECT command. It also handles updates by executing the INSERT, UPDATE, or DELETE commands to sync changes back to the database.
    2. CommandBuilder: Automatically generates the INSERT, UPDATE, and DELETE SQL commands for the DataAdapter. This eliminates the need for manually writing those SQL commands for each CRUD operation.
    3. DataSet: Serves as an in-memory representation of data that can hold multiple tables and their relationships. It can be manipulated offline and later synchronized with the database.

    Advantages of Using the Disconnected Model

    • Offline Data Handling: Since the DataSet is disconnected from the database, the data can be manipulated offline and can be updated later when the application reestablishes the connection.
    • Improved Performance: Reduces the number of database calls, as data is retrieved in bulk and can be manipulated in memory. This is beneficial when working with large datasets.
    • Separation of Concerns: The business logic can work with data without worrying about database connections or SQL queries, improving maintainability and testability.
    • Data Binding: The DataSet can be easily bound to UI controls, making it convenient for user interfaces that display data.

    Summary of Components

    Component Description
    DataSet An in-memory representation of data that can hold multiple tables and their relationships. Can be filled from a database and used offline.
    DataAdapter Fills the DataSet with data from the database and pushes changes back to the database.
    CommandBuilder Automatically generates SQL commands for the DataAdapter to perform INSERT, UPDATE, and DELETE operations.

    In a disconnected environment, these components work together to allow applications to manage and manipulate data offline, then sync changes to the database when necessary.

    ← Previous topic 9
    Introduction to ADO.Net: SQL Injection, parameterized queries
    Next topic 11 →
    Introduction to delegate: Multicast delegates

    Past Papers

    Open this section to view and download past papers

    Click on Show Past Papers to load available exam papers.

    Reading Progress
    0%
    6mremaining
    1.1kwords
    Intermediatelevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Enterprise Application Development