alert('Oh shit !!!! Javascript is disabled!!!! ');


Showing posts with label Ado.Net Blog. Show all posts
Showing posts with label Ado.Net Blog. Show all posts

The use of data adapter.?

The use of data adapter.?

data adapter:-The DataAdapter serve as a bridge between a DataSet and data source for retrieving and saving data. The DataAdapter provides this bridge by using Fill to load data from the data source into the DataSet and using Update to send changes made in the DataSet back to the data source.  The data adapter objects connect a command objects to a Dataset object. They provide the means for the exchange of data between the data store and the tables in the DataSet.An OleDbDataAdapter object is used with an OLE-DB provider
A SqlDataAdapter object uses Tabular Data Services with MS SQL Server.

Namespace:  System.Data.Common
Assembly:  System.Data (in System.Data.dll)

Data adapter Flow  Architecture

The DataAdapter acts as a bridge between the disconnected DataSet and the data source. It exposes two interfaces; the first of these,IDataAdapter that  defines methods for populating a DataSet with data from the data source and for updating the data source with changes made to the DataSet on the client. The another interface is  IDbDataAdapter that  defines four properties, each of type IDbCommand. These all properties each set or return a command object specifying the command to be executed when the data source is to be queried or updated:

 

Constructors of Data Adapter?

There are two constructor:

Name Description
DataAdapter(DataAdapter) Initializes a new instance of a DataAdapter class from an existing object of the same type.
DataAdapter Initializes a new instance of a DataAdapter class.

Property  of Data Adapter?

there are following main property:

                                              Name           Description
TableMappings Gets a collection that provides the master mapping between a source table and a DataTable.
Container Gets the IContainer that contains the Component. (Inherited from Component.)
DesignMode Gets a value that indicates whether the Component is currently in design mode. (Inherited from Component.)
Events Gets the list of event handlers that are attached to this Component. (Inherited from Component.)

AcceptChangesDuringUpdate

Gets or sets whether AcceptChanges is called during a Update.
 

AcceptChangesDuringFill

Gets or sets a value indicating whether AcceptChanges is called on a DataRow after it is added to the DataTable during any of the Fill operations.

Method  of Data Adapter?

there are following main method:-

                                                               Name                                                     Description
Dispose                                      Releases all resources used by the Component (Inherited fromComponent.)                                     
Fill(DataSet) Adds or refreshes rows in the DataSet to match those in the data source.
Finalize Releases unmanaged resources and performs other cleanup operations before the Component is reclaimed by garbage collection. (Inherited from Component.)
GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
GetType Gets the Type of the current instance. (Inherited from Object.)

Event of Data Adapter?

There are two events:-

Name Description
Disposed Occurs when the component is disposed by a call to the Dispose method. (Inherited from Component.)
FillError Returned when an error occurs during a fill operation.
 

Interface Implementation of Data Adapter?

Name Description
IDataAdapter.TableMappings Indicates how a source table is mapped to a dataset table.

Basic method of Data Adapter?

There are three basic method in data adopter:-

(i)Fill:-Fill  method executes the SelectCommand to fill the DataSet object with data from the data source,Depending on whether there is a primary key in the DataSet, the ‘fill’ can also be used to update an existing table in a DataSet with changes made to the data in the original datasource.

(ii)FillSchema:-Fill Schema method executes the SelectCommand to extract the schema of a table from the data source and  creates an empty table in the DataSet object with all the corresponding constraints.

(iii0Update:-Update method executes the InsertCommand, UpdateCommand, or DeleteCommand to update the original data source with the changes made to the content of the DataSet.

(iv) Dispose :- releases all the resources

The steps involved to fill a dataset?

The steps involved to fill a dataset?

There are following  steps  to  fill  a  dataset:-

(i). Create a connection object.
(ii). Create an adapter by passing the string query and the connection object as parameters.
{iii). Create a new object of dataset.
(iv). Call the Fill method of the adapter and pass the dataset object.

We can  check that some changes have been made to dataset since it was loaded?

There are following way to check that some changes have been made to dataset since it was loaded:-

(i). GetChanges: gives the dataset that has changed since newly loaded or since Accept changes has been executed.
{ii}. HasChanges: this returns a status that tells if any changes have been made to the dataset since accept changes was executed.

How can we add/remove row’s in “DataTable” object of “DataSet”?

Using NewRow method we can add row's in a data table  object of dataset.Remove method of the DataRowCollection is used to remove a ‘DataRow’ object from ‘DataTable’.
RemoveAt method of the DataRowCollection is used to remove a ‘DataRow’ object from ‘DataTable’ per the index specified in the DataTable.

UPDATING THE DATABASE USING A DATASET

The underlying database can be updated directly by passing SQL INSERT/UPDATE/ DELETE statements, or stored procedure calls, through to the managed provider. It

We can also be updated using a DataSet.

The steps are:

  1. Create and fill the DataSet with one or more DataTables

  2. Call DataRow.BeginEdit on a DataRow

  3. Make changes to the row’s data

  4. Call DataRow.EndEdit

  5. Call SqlDataAdapter.Update to update the underlying database

  6. Call DataSet.AcceptChanges (or DataTable.AcceptChanges orDataRow.AcceptChanges)

Example :-UPDATING THE DATABASE USING A DATASET

To update the database directly, we can use the SqlCommand object, which allows us to execute SQL INSERT, UPDATE, and DELETE statements against a database.


Using System;
using System.Data;
using System.Data.SqlClient;
public class empdel {
public static void Main() {
SqlConnection con = new SqlConnection(
@"server=(local)\computer;database=emp;trusted_connection=yes"
);
string sql = "DELETE FROM emp WHERE emp_name = 'Ashok'";
SqlCommand cmd = new SqlCommand(sql, con);
con.Open();
int i = cmd.ExecuteNonQuery();
con.Close();
Console.WriteLine("{0} record(s) deleted.", i);
}
}

To load multiple tables in a DataSet


DataSet ds = new DataSet();

SqlDataAdapter da = new SqlDataAdapter ("Emp", this.Connection);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Parameters.AddWithValue ("@EId", EId);
da.TableMappings.Add ("Table", ds.xval.TableName);
da.Fill (ds); 

ADO.NET Code showing Dataset storing multiple tables.


DataSet ds = new DataSet();
ds.Tables.Add(dt1);
ds.Tables.Add(dt2);
ds.Tables.Add(dt3);
ds.Tables.Add(dt4);
ds.Tables.Add(dt5);
..................
.................
..................
ds.Tables.Add(dtn);; 

 

Dataset object in ADO .NET

Dataset object in ADO .NET

The DataSet object is a disconnected storage.DataSet is a disconnected  in-memory representation of data. It can be considered as a local copy of the relevant portions of the database. The DataSet is persisted in memory and the data in it can be manipulated and updated independent of the database. It represents related tables, constraints, and relationships among the tables. DataSet reads and writes data and schema as XML documents.The DataSet object is a disconnected storage.It is used for manipulation of relational data. The DataSet is filled with data from the storeWe fill it with data fetched from the data store. Once the work is done with the dataset, connection is reestablished and the changes are reflected back into the store.

                                

                                   

          

ADO.NET DataSet can contain more than one table and also contains information about table relationships, the columns they contain, and any   constraints that apply. Each table in a DataSet can contain multiple rows. Once data is retrieved from the database into a DataSet object, an application can disconnect from the database before processing the DataSet. This is an important feature of the ADO.NET DataSet. It gives us an in-memory, disconnected copy of a portion of the database which we can process without retaining an active connection to the database server.

Creating and using a DataSet

The typical steps in creating and using a DataSet are:

(i)Create a DataSet object

(ii) Connect to a database

(iii)Fill the DataSet with one or more tables or views

(iv)Disconnect from the database

(v)Use the DataSet in the application

Example of  DataSet


using System;
using System.Data;
using System.Data.SqlClient;
public class empcount {
public static void Main() {
// change the following connection string, as necessary...
string con =
@"server=(local)\kamal;database=Emp;trusted_connection=yes";
DataSet ds = new DataSet("EmpDataSet");
SqlDataAdapter sad;
string sl;
sl = "SELECT COUNT(*) AS cnt FROM employee";
sad = new SqlDataAdapter(sl, con);
sad.Fill(ds, "emp_count");
sl = "SELECT COUNT(*) AS cnt FROM compocation";
sad = new SqlDataAdapter(sl, con);
sad.Fill(ds, "comploc_count");
int totalemp = (int) ds.Tables["emp_count"].Rows[0]["cnt"];
int comploc = (int) ds.Tables["comploc_count"].Rows[0]["cnt"];
Console.WriteLine(
"There are {0} employee, {1} complocation .",
totalemp ,
 comploc,

);
}
}

 

Handling Connection Events

Handling Connection Events

Both the OLE DB and the SQL Server Connection objects provide two events:

1)StateChange

2)InfoMessage.

1)StateChange

the StateChange event fires whenever the state of the Connection object changes. The event passes a StateChangeEventArgs to its handler, which, inturn, has two properties: OriginalState and CurrentState. The possible values for

OriginalState and CurrentState are:

Connection States  Meaning
Broken

TheConnecton is open, but not functional. It maybe closed and reopened

 

Closed The Connection is closed
Connecting

The Connection is in the process of connecting, but has not yet been

 

Executing Executing the command
Fetching Retrieving the data
Open Open the connection

To display the previous and current Connection states for each of the two Connection objects: Select OleDbConnection1 in the Class Name combobox of the editor and the StateChange event in the Method Name combobox.


private void oleDbConnection1_StateChange (object sender,StateChangeEventArgs
e) { string s; s = "The Connection State is changing from " + e.OriginalState.ToString() + " to " + e.CurrentState.ToString(); MessageBox.Show(s); } private void SqlDbConnection1_StateChange (object sender, StateChangeEventArgs
e) { string s1; s1 = "The Connection State is changing from " + e.OriginalState.ToString() + " to " + e.CurrentState.ToString(); MessageBox.Show(s1); }

 Add the code to connect the event handlers to the:-

ConnectionProperties sub:

 this.oleDbConnection1.StateChange += newSystem.Data.StateChangeEventHandler(this.oleDbConnection1_StateChange);

this.SqlDbConnection1.StateChange += new System.Data.StateChangeEventHandler(this.SqlDbConnection1_StateChange);

. Save and run the program. Change the Connection Type and then click the Test button.

The application displays two MessageBoxes as the Connection is opened and closed.

2)InfoMessage

The InfoMessage event is triggered when the data source returns warnings. The information passed to the event handler depends on the Data Provider.

The SQLCONNECTION OBJECT

The SQLCONNECTION OBJECT

A SqlConnection is an object,as any other C# object.  we  just declare and instantiate the SqlConnection all at the same time, as shown below:

SqlConnection con = new SqlConnection(
    "Data Source=(local);Initial Catalog=Emp;Integrated Security=sspi");

The SqlConnection object instantiated above  by using  a constructor with a single argument of type string and this argument is called a connection string. 

There are four Connection String Parameter Name:-

1)Data Source: Data Source Identifies the server and it  Could be local machine, machine domain name, or IP Address.

2)Initial Catalog: Database name

3)Integrated Security: Integrated Security set to SSPI to make connection with user's Windows login.

4)User ID:  Name of user configured in SQL Server.

5)Password: Password matching SQL Server User ID.

The following shows a connection string, using the User ID and Password parameters:

SqlConnection conn = new SqlConnection(
"Data Source=DatabaseServer;Initial Catalog=Northwind;User ID=YourUserID;Password=YourPassword");

Using a SqlConnection

The aim of creating a SqlConnection object is so we can enable other ADO.NET code to work with a database and  SqlCommand and a SqlDataAdapter take it a connection object as a parameter.  The sequence of operations occurring in the lifetime of a SqlConnection are given below:

  1. Instantiate the SqlConnection.
  2. Open the connection.
  3. Pass the connection to other ADO.NET objects.
  4. Perform database operations with the other ADO.NET objects.
  5. Close the connection.
The Open() Method:

The Open() method of the Connection object establishes a connection  to the data source.,because database connections are a very expensive resource memory-wise, so we should only call the Open() method just before we're ready to retrieve the data. This ensures that the connection is not open any longer than it needs to be.

The Close() Method

After we are done retrieving data,we should call the Close() method of the Connection object. This closes the connection to the database.

Example Using  SQLCONNECTION Object


using System;
using System.Data;
using System.Data.SqlClient;

class sqlConnectivityexample
{
    static void Main()
    {
      
        SqlConnection conn = new SqlConnection(
            "Data Source=(local);Initial Catalog=Emp;Integrated Security=SSPI");

        SqlDataReader rdr = null;

        try
        {
            // 2. Open the connection
            conn.Open();

            // 3. Pass the connection to a command object
            SqlCommand cmd = new SqlCommand("select * from emp", conn);

            //
            // 4. Use the connection
            //

            // get query results
            rdr = cmd.ExecuteReader();

            // print the CustomerID of each record
            while (rdr.Read())
            {
                Console.WriteLine(rdr[0]);
            }
        }
        finally
        {
            // close the reader
            if (rdr != null)
            {
                rdr.Close();
            }

            // 5. Close the connection
            if (conn != null)
            {
                conn.Close();
            }
        }
    }
}

Command Constructors

Command Constructors

  • New(): Creates a new, default instance of the Data Command
  • New(Command): Creates anew Data Command with the Command Text set to the string specified in command.
  • New(Command, Connection): Creates a new Data Command with the Command Text set to the string specified in Command and the Connection property set to the SqlConnection specified inConnection
  • New(Command, Connection, Transaction): Creates anew Data Command with the CommandText set to the string specified in Command the Connection property set to the Connection specified in Connection,and the Transactionproperty set to the transaction specified in Transaction.
     

Example of SqlCommand Object


using System;
 using System.Data;
 using System.Data.SqlClient;
 
 class SqlCommandexample
 {
     SqlConnection conn;
 
     public SqlCommandDemo()
     {
         // Instantiate the connection
         conn = new SqlConnection(
            "Data Source=computer;Initial Catalog=Emp;Integrated Security=SSPI");
     }
 
     // call methods that demo SqlCommand capabilities
     static void Main()
     {
         SqlCommandexample scd = new SqlCommandexampleo();
 
         Console.WriteLine();
         Console.WriteLine("Categories Before Insert");
         Console.WriteLine("------------------------");
 
         // use ExecuteReader method
         scd.ReadData();
 
         // use ExecuteNonQuery method for Insert
         scd.Insertdata();
         Console.WriteLine();
         Console.WriteLine("Categories After Insert");
         Console.WriteLine("------------------------------");
 
        scd.ReadData();
 
         // use ExecuteNonQuery method for Update
         scd.UpdateData();
 
         Console.WriteLine();
         Console.WriteLine("Categories After Update");
         Console.WriteLine("------------------------------");
 
         scd.ReadData();
 
         // use ExecuteNonQuery method for Delete
         scd.DeleteData();
 
         Console.WriteLine();
         Console.WriteLine("Categories After Delete");
         Console.WriteLine("------------------------------");
 
         scd.ReadData();
 
         // use ExecuteScalar method
         int numberOfRecords = scd.GetNumberOfRecords();
 
         Console.WriteLine();
         Console.WriteLine("Number of Records: {0}", numberOfRecords);
     }
 
     /// <summary>
     /// use ExecuteReader method
     /// </summary>
     public void ReadData()
     {
        SqlDataReader rdr = null;
 
         try
         {
             // Open the connection
             conn.Open();
 
             // 1. Instantiate a new command with a query and connection
             SqlCommand cmd = new SqlCommand("select EmpName from Emp", conn);
 
             // 2. Call Execute reader to get query results
             rdr = cmd.ExecuteReader();
 
             // print the CategoryName of each record
             while (rdr.Read())
             {
                 Console.WriteLine(rdr[0]);
             }
         }
         finally
         {
             // close the reader
             if (rdr != null)
             {
                 rdr.Close();
             }
 
             // Close the connection
             if (conn != null)
             {
                 conn.Close();
             }
         }
     }
 
     /// <summary>
     /// use ExecuteNonQuery method for Insert
     /// </summary>
     public void Insertdata()
     {
         try
         {
             // Open the connection
             conn.Open();
 
             // prepare command string
             string insertString = @"
                 insert into Emp
                 (EmpName, post)
                 values ('Raj', 'A\c')";
 
             // 1. Instantiate a new command with a query and connection
             SqlCommand cmd = new SqlCommand(insertString, conn);
 
             // 2. Call ExecuteNonQuery to send command
             cmd.ExecuteNonQuery();
         }
         finally
         {
             // Close the connection
             if (conn != null)
             {
                 conn.Close();
             }
         }
     }
 
     /// <summary>
     /// use ExecuteNonQuery method for Update
     /// </summary>
     public void UpdateData()
     {
         try
         {
             // Open the connection
             conn.Open();
 
             // prepare command string
             string updateString = @"
                 updateEmp
                 set EmpName = 'Anil'
                 where EmpName = 'Raj'";
 
             // 1. Instantiate a new command with command text only
             SqlCommand cmd = new SqlCommand(updateString);
 
             // 2. Set the Connection property
             cmd.Connection = conn;
 
             // 3. Call ExecuteNonQuery to send command
             cmd.ExecuteNonQuery();
        }
         finally
         {
             // Close the connection
             if (conn != null)
             {
                 conn.Close();
             }
         }
     }
 
     /// <summary>
     /// use ExecuteNonQuery method for Delete
     /// </summary>
     public void DeleteData()
     {
         try
         {
             // Open the connection
             conn.Open();
 
             // prepare command string
             string deleteString = @"
                 delete from Emp
                 where EmpName = 'Ashish'";
 
             // 1. Instantiate a new command
             SqlCommand cmd = new SqlCommand();
 
             // 2. Set the CommandText property
             cmd.CommandText = deleteString;
 
             // 3. Set the Connection property
             cmd.Connection = conn;
 
             // 4. Call ExecuteNonQuery to send command
             cmd.ExecuteNonQuery();
         }
         finally
         {
             // Close the connection
             if (conn != null)
             {
                 conn.Close();
             }
         }
     }
 
     /// <summary>
     /// use ExecuteScalar method
     /// </summary>
     /// <returns>number of records</returns>
     public int GetNumberOfRecords()
     {
         int count = -1;
 
         try
         {
             // Open the connection
             conn.Open();
 
             // 1. Instantiate a new command
             SqlCommand cmd = new SqlCommand("select count(*) from Emp", conn);
 
             // 2. Call ExecuteScalar to send command
             count = (int)cmd.ExecuteScalar();
         }
         finally
         {
            // Close the connection
             if (conn != null)
             {
                 conn.Close();
             }
         }
         return count;
     }
 }

The SQLCOMMAND OBJECT

The SQLCOMMAND OBJECT

When we have a more complex query that retrieves records from different tables, or don't want the UPDATE command to check for changes in the database before updating it, we can specify our own SQL commands.The Command object enables  to execute queries against  data source. in order to retrieve data, you must know the schema of your database as well as how to build a valid SQL query. The Command objects allow developers to specify parameters dynamically at run time. When defining the SQL statement we use a placeholder instead of a particular value. Then we use the Parameters collection of the Command object to define the dynamic column value.The SqlCommand object must be used in conjunction with the SqlConnection object

Creating a SqlCommand Object

SqlCommand cmd = new SqlCommand("select CategoryName from Categories", new sqlconnection(parameter));

Querying Data

using a SQL select command

1)Instantiate a new command with a query and connection
SqlCommand cmd =
new SqlCommand("select EmployeeName from Emp", conn);

 2. Call Execute reader to get query results
SqlDataReader dr = cmd.ExecuteReader();

Inserting Data

using a SQL insert command,To insert data into a database, use the ExecuteNonQuery method of the SqlCommand object.

1)Insert command string
 
string insertString = @"
     insert into Emp
     (EmpName, Post)
     values ('Aditya', 'S\w Engg')";
 
 
2.)Instantiate a new command with a query and connection
 
SqlCommand cmd = new SqlCommand(insertString, conn);
 
 
3) Call ExecuteNonQuery to send command
 
cmd.ExecuteNonQuery();

Updating Data

using a SQL update command,To update data into a database, use the ExecuteNonQuery method of the SqlCommand object.

1)prepare command string
 
string updateString = @"
     update Emp
     set EmpName = 'Ashish'
     where CategoryName = 'Raj'";
 
2) Instantiate a new command with command text only
 
SqlCommand cmd = new SqlCommand(updateString,conn);
 
 
3) Call ExecuteNonQuery to send command
 
cmd.ExecuteNonQuery();

Deleting Data

using a SQL delete command,To delete data into a database, use the ExecuteNonQuery method of the SqlCommand object.

1) delete command string
 
string deleteString = @"
     delete from Emp
     where EmpName = 'Ashish'";
 
2) Instantiate a new command
 
SqlCommand cmd = new SqlCommand();
 
3) Set the CommandText property
 
cmd.CommandText = deleteString;
 
4) Set the Connection property
 
cmd.Connection = conn;
 
5)Call ExecuteNonQuery to send command
 
cmd.ExecuteNonQuery();

Getting Single Values

    For getting a single value we can use  count, sum, average, or other aggregated value from a data set.

1) Instantiate a new command
 
SqlCommand cmd = new SqlCommand("select count(*) from Categories", conn);
 
2) Call ExecuteNonQuery to send command
 
int count = (int)cmd.ExecuteScalar();

Component classes

Component classes

1-The Connection Object

The Connection object creates the connection to the database. Microsoft Visual Studio .NET provides two types of Connection classes first is  the SqlConnection object, which is designed specifically to connect to Microsoft SQL Server 7.0 or later, and the other is  OleDbConnection object, it can provide connections to a wide range of database types like Microsoft Access and Oracle. The Connection object contains all of the information required to open a connection to the database.

2-The Command Object

It is represented by two corresponding classes: SqlCommand and OleDbCommand. Command objects are used to execute commands to a database across a data connection. Command objects can be used to execute stored procedures on the database, SQL commands, and  return complete tables directly. It provide three methods which are used to execute commands on the database:

(i)-ExecuteNonQuery: Executes commands that have no return values such as INSERT, UPDATE or DELETE
(ii)ExecuteScalar:
Returns a single value from a database query
(iii)ExecuteReader:
Returns a result set by way of a DataReader object

3-The DataReader Object

The DataReader object provides a forward-only, read-only, connected stream recordset from a database. Unlike other components of the Data Provider, DataReader objects cannot be directly instantiated.The DataReader is returned as the result of the Command object's ExecuteReader method. The SqlCommand.ExecuteReader method returns a SqlDataReader object, and the OleDbCommand.ExecuteReader method returns an OleDbDataReader object. The DataReader can provide rows of data directly to application logic when we do not need to keep the data cached in memory because only one row is in memory at a time, the DataReader provides the lowest overhead in terms of system performance but requires the exclusive use of an open Connection object for the lifetime of the DataReader.

4:-The DataAdapter Object

The DataAdapter is the class at the core of ADO .NET's disconnected data access. It is used  to fill a DataTable or DataSet with data from the database with it's Fill method. After the memory-resident data has been manipulated.Tthe DataAdapter can commit the changes to the database by calling the Update method. The DataAdapter provides four properties that represent database commands:

(i) Select Command
(ii) Insert Command
(iii) Delete Command
(iv) Update Command

When the Update method is called, changes in the DataSet are copied back to the database and the appropriate InsertCommand, DeleteCommand, or UpdateCommand is executed. 

Define connected and disconnected data access in ADO.NET

connected data access in ADO.NET :-Data reader is based on the connected architecture for data access. Does not allow data manipulation

Disconnected data access in ADO.NET:-Dataset supports disconnected data access architecture. This gives better performance results.

Describe CommandType property of a SQLCommand in ADO.NET.

  CommandType property:-CommandType property  is a property of Command object that can be set to Text, Storedprocedure. If it is Text, the command executes the database query. When it is StoredProcedure, the command runs the stored procedure. A SqlCommand is an object that allows specifying what is to be performed in the database.

Access database at runtime using ADO.NET

Access database at runtime using Sqlconnection in ADO.NET


Using System.Data.SqlClient;
SqlConnection con = new SqlConnection(connectionString)
con.Open();
string stringQuery = "select EmployeeName from emp";
SqlCommand cmd = new SqlCommand(stringQuery, con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
        Console.WriteLine(dr [0]);
}
dr.Close(); 
con.Close();



The Connection String in the App.Config File


<connectionStrings>
<add name="DragDropWinApp.Settings.TestConnectionString"
connectionString=
"Data Source=(local);Initial Catalog=emp;Integrated Security=True"
providerName="System.Data.SqlClient" />


THE ADO.NET Architecture?

THE ADO.NET  Architecture?

Data Access in ADO.NET relies on two components: DataSet and Data Provider.

DataSet

The dataset is a disconnected storage and  disconnected in-memory representation of data. It can be used as a local copy of the relevant portions of the database. The DataSet is persisted in memory and the data in it can be manipulated and updated independent of the database. When the use of this DataSet is finished, changes can be made back to the central database for updating. The data in DataSet can be loaded from any valid data source like Microsoft SQL server database, an Oracle database or from a Microsoft Access database.

Data Provider

The Data Provider is responsible for  maintaining  and providing the connection to the database. A DataProvider is a set of related components that work together to provide data in an efficient and performance driven manner. The .NET Framework currently comes with two DataProviders: the SQL Data Provider which is designed only to work with Microsoft's SQL Server 7.0 or later and the OleDb DataProvider which allows us to connect to other types of databases like Access and Oracle. Each DataProvider consists of the following component classes:

The Connection :-TheConnection object which provides a connection to the database
The Command :-The Command object which is used to execute a command
The DataReader:- The DataReader object which provides a forward-only, read only, connected recordset
The DataAdapter :-The DataAdapter object which populates a disconnected DataSet with data and performs update

A connection object create the connection for the application with the database. The command object provides direct execution of the command to the database. If the command returns more than a single value, the command object returns a DataReader to provide the data. Alternatively, the DataAdapter can be used to fill the Dataset object. The database can be updated using the command object or the DataAdapter.

 

Introduction to Ado.Net blog

Introduction of ADO  .NET

ADO stands for ActiveX  Data Object .ADO.NET is an object-oriented set of libraries that allows  to interact with data sources.  The data source is a database, but it could also be a text file, an Excel spreadsheet, or an XML file.ADO .NET consists of classes that allow a .NET application to connect to the data source, executes commands and manage disconnected data. One of the key Differences between ADO.NET and other database technologies is how it deals with Challenge with different data sources, that means, the code you use to connect to an SQL Database will not differ that much to the one connecting to an Oracle Database.

ADO.NET is Microsoft's platform for data access in its new .NET Framework. It  is scalable, interoperable, and familiar enough to ADO developers to be immediately usable and  By design, the ADO.NET object model and many of the ADO.NET code constructs will look very familiar to ADO developers.

Benefits of ADO.NET ?

ADO.NET offers numerous advantages compared to its previous versions of ADO and other data access components.

1. Interoperability- The ability to communicate across  heterogeneous environment.

2. Maintainability- Various substantial, architectural changes and transformations required in the life of a deployed system can be easily carried out, if the application is implemented in ADO.NET using datasets.

3. Programmability- ADO.NET data components enables you program more quickly and with fewer mistakes in Visual Studio encapsulate data access functionality. It also allows you to access data through typed programming as ADO.NET data classes generated by the designer tools result in the typed datasets.

4. Performance- ADO.NET datasets offer performance advantages, for disconnected applications, over ADO disconnected record sets.

5. Scalability- ADO.NET enables scalability by helping the programmers to conserve limited resources.

6.Productivity-The ability to quickly develop  robust data access applications using ADO .NET's  rich and extensible component object model.

THE ADO.NET NAMESPACES

ADO .NET has several namespaces containing classes that represent database objects such as connections, commands, and datasets. Perhaps the most important of these

classes is the new XML-enabled DataSet which provides a relational data store and astandard API independent of any underlying database management system.

.NET Framework Namespaces Involved in Data Access:-

NAMESPACE DESCRIPTION
System.Data Provides base classes for ADO.NET, focused on the DataSet class and its child classes, such as DataRow, DataColumn, and DataRelation.
System.Data.SqlClient The SQL Server .NET data provider.
System.Data.OleDb The OLE DB .NET data provider.
System.Data.Common Provides classes that are shared by all .NET data providers. Many of these classes are abstract and may be used to create custom data providers.
System.Data.SqlTypes Provides classes for native data types in SQL Server.
System.Xml Provides classes for processing XML.
System.Xml.Schema Provides classes for processing XML Schema Definition (XSD) schema files.
System.Xml.Xsl Provides classes for processing Extensible Stylesheet Transformation (XSLT) transforms.

There are two managed providers:-

1-The Oledb

2-Sql server

The OLE DB and SQL Server managed providers

DataSet provides a stand-alone entity separate from the underlying store, in most cases it will get its data from a managed provider whose role is to connect,

fill, and persist the DataSet to and from a data store. .NET offers two such providers embodied in the following two namespaces:

• System.Data.SqlClient—Used to talk directly to Microsoft SQL Server.

• System.Data.OleDb—Used to talk to any other provider that supports OLE DB (a COM-based API for accessing data).

previous

Home

Next

Ado.Net Blog Content

  1. Introduction of ADO.NET

  2. THE ADO.NET  Architecture

  3. Component classes

  4. The SQLCOMMAND OBJECT

  5. Command Constructors

  6. The SQLCONNECTION OBJECT

  7. Handling Connection Events

  8. Dataset object in ADO .NET

  9. The steps involved to fill a dataset?

  10. Data adapter