BCA / B.Tech 14 min read

ADO.NET | What is ADO.NET?

Introduction of ADO.NET in Hindi | Introduction to ADO.NET:


  • ADO.NET (ActiveX Data Objects .NET) is a data access technology developed by Microsoft, which is part of the .NET Framework.
  • It is used to access and manage data from a database. ADO.NET supports a disconnected architecture, which makes it fast and effective.
  • It can be used with SQL Server, Oracle, OLE DB, and XML data sources.
  • ADO.NET is an important part of the .NET Framework that provides the facility to interact with a database efficiently.
  • Due to its disconnected architecture and object model, it is suitable for handling data easily.
  • ADO.NET is mainly useful for reading, writing, updating, and deleting data.
ADO.NET in Hindi | What is ADO.NET?

Features of ADO.NET in Hindi | Features of ADO.NET:

  • Disconnected Architecture: Allows caching data and using it later.
  • Data Provider: Different class libraries for interfacing with data sources.
  • XML Support: Facility to read and manipulate data with XML.
  • Scalability: Capable of working with large amounts of data.
Data Providers in ADO.NET in Hindi | Data Providers:

ADO.NET data providers are used to connect to a database and access data. Each provider works with a specific data source.

Main Data Providers in ADO.NET in Hindi | Main Data Providers:

  • SQL Server Data Provider: For SQL Server.
  • Namespace: System.Data.SqlClient
  • OLE DB Data Provider: For other OLE DB compatible data sources.
  • Namespace: System.Data.OleDb
  • ODBC Data Provider: For ODBC compatible data sources.
  • Namespace: System.Data.Odbc
  • Oracle Data Provider: For Oracle Database.
  • Namespace: System.Data.OracleClient
ADO.NET Objects in Hindi | ADO.NET Objects:

There are various objects in ADO.NET to handle data.

  • Connection Object: Creates a connection with the data source.
  • Example: SqlConnection
  • Command Object: Executes SQL commands.
  • Example: SqlCommand
  • DataReader Object: Reads data in a forward-only manner.
  • Example: SqlDataReader
  • DataAdapter Object: Acts as a bridge between the data source and the DataSet.
  • DataSet Object: Caches disconnected data.

Program of ADO.NET in Hindi | ADO.NET Programs in C#:

Reading data from SQL Server in Hindi |  Reading data from SQL Server:

using System;
using System.Data.SqlClient;

class Program
{
    static void Main()
    {
        string connectionString = "Data Source=YOUR_SERVER;Initial Catalog=YOUR_DATABASE;Integrated Security=True";
        string query = "SELECT * FROM Students";

        using (SqlConnection connection = new SqlConnection(connectionString))
        {
            SqlCommand command = new SqlCommand(query, connection);

            connection.Open();
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Console.WriteLine($"ID: {reader["ID"]}, Name: {reader["Name"]}, Age: {reader["Age"]}");
            }

            reader.Close();
        }
    }
}


Data Inserting:

using System;
using System.Data.SqlClient;

class Program
{
    static void Main()
    {
        string connectionString = "Data Source=YOUR_SERVER;Initial Catalog=YOUR_DATABASE;Integrated Security=True";
        string query = "INSERT INTO Students (Name, Age) VALUES (@Name, @Age)";

        using (SqlConnection connection = new SqlConnection(connectionString))
        {
            SqlCommand command = new SqlCommand(query, connection);
            command.Parameters.AddWithValue("@Name", "Rahul");
            command.Parameters.AddWithValue("@Age", 20);

            connection.Open();
            int rowsAffected = command.ExecuteNonQuery();
            Console.WriteLine($"{rowsAffected} row(s) inserted successfully.");
        }
    }
}

Data Update:

using System;
using System.Data.SqlClient;

class Program
{
    static void Main()
    {
        string connectionString = "Data Source=YOUR_SERVER;Initial Catalog=YOUR_DATABASE;Integrated Security=True";
        string query = "UPDATE Students SET Age = @Age WHERE Name = @Name";

        using (SqlConnection connection = new SqlConnection(connectionString))
        {
            SqlCommand command = new SqlCommand(query, connection);
            command.Parameters.AddWithValue("@Name", "Rahul");
            command.Parameters.AddWithValue("@Age", 21);

            connection.Open();
            int rowsAffected = command.ExecuteNonQuery();
            Console.WriteLine($"{rowsAffected} row(s) updated successfully.");
        }
    }
}