Articles → ADO.NET → Dataset In ADO.NET

Dataset In ADO.NET






What Is A Dataset?





Example


using System;
using System.Data;

namespace datasetdemo
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a new Dataset
            DataSet dataSet = new DataSet();

            // Create a DataTable
            DataTable table = new DataTable("Employees");

            // Define columns
            table.Columns.Add("ID", typeof(int));
            table.Columns.Add("Name", typeof(string));

            // Add data to the DataTable
            table.Rows.Add(1, "John");
            table.Rows.Add(2, "Jane");

            // Add the DataTable to the Dataset
            dataSet.Tables.Add(table);

            // Access data from the Dataset
            foreach (DataRow row in dataSet.Tables["Employees"].Rows)
            {
                Console.WriteLine($"ID: {row["ID"]}, Name: {row["Name"]}");
            }

            Console.ReadLine();

        }
    }
}



Output


Picture showing the output of dataset in ado.net



Posted By  -  Karan Gupta
 
Posted On  -  Saturday, May 4, 2024

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250