ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Enterprise Application Development
    EC-332
    Progress0 / 37 topics
    Topics
    1. Overview of Enterprise Application Development: Microsoft technology history2. Introduction to .NET and its architecture3. Concept of MSIL, CLR, CLS, CTS4. Introduction to .NET framework: Managed and Unmanaged Code5. .Net Assembly6. Introduction to C# fundamentals7. Boxing and Unboxing8. Implementing multi-tier architecture9. Introduction to ADO.Net: SQL Injection, parameterized queries10. Usage of data set, Data adapter and command builder in disconnected model11. Introduction to delegate: Multicast delegates12. Introduction to windows forms13. HTML14. Introduction to javascript: javascript and its data types, variables, functions15. Debugging javascript using Firebug16. Introduction to various object models: Browser's Object (BOM), Document Object Model17. Introduction to Jquery: Jquery effects18. Introducing LINQ: LINQ to Objects, LINQ to SQL19. Query syntax, Operations (projection, filtering and join) using Linq Queries20. Introduction to ADO.NET entity framework: The entity data model, CSDL21. Eager vs lazy loading, POCO classes, DBContext API22. Querying entity data models23. Introduction to ASP.NET MVC24. MVC application structure, Controllers overview25. Action Methods, Parameterized action methods26. Introduction to razor syntax27. Code expressions, Code Blocks, Implicit Vs Explicit Code Expression28. Data annotations, Client and Server Side Validation29. Validation and model binding, Validation and model state30. MVC Membership, Authorization and security31. Introduction to service-oriented architecture: SOAP, WSDL32. Service contract, Data contract, XML, WCF bindings33. ABC of WCF, Restful services34. Consuming rest services (CRUD operations) using Jquery AJAX and JSON35. Introduction to web API36. Example of web API using CRUD Example37. MVC routing
    EC-332›Usage of data set, Data adapter and command builder in disconnected model
    Enterprise Application DevelopmentTopic 10 of 37

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

    6 minread
    1,084words
    Intermediatelevel

    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 load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time6 min
      Word count1,084
      Code examples0
      DifficultyIntermediate