javascript
Brief description  about Online courses   join in Online courses
OR

Accessing database

Agrim  Gupta
Agrim Gupta
Net Developers
.NET is an integral part of many applications running on Windows and provides common functionality for those applications to run. This download is for people who need .NET to run an application on their computer. For developers, the .NET Framework provides a comprehensive and consistent programming model for building applications that have visually stunning user experiences and seamless and secure communication.

Database Concepts

Database is the media to store data. If you have an application that has to store and retrieve data, your application must be using a database.

A File is the simplest form of saving the data in the disk, but is not the most efficient way of managing application data. A database is basically a collection of one or more files, but in a custom format, and data is organized in a specific format such a way that it can be retrieved and stored very efficiently.

Some examples for databases are :
  • MS Access
  • SQL Server
  • Oracle
  • MS Access is a very light weight database provided by Microsoft for applications with less number of users and relatively small quantity of data. MS Access saves data into database files with the extension .mdb. Usually, MS Access comes along with MS Office package. If you already have the .mdb database file, you can freely use it with your application and you do not need MS Access software. The MS Access software is required only if you want to directly open the database and manipulate the data or change the database schema.

    ADO.NET

    ADO.NET is the data access model that comes with the .NET Framework. ADO.NET provides the classes required to communicate with any database source (including Oracle, Sybase, Microsoft Access, Xml, and even text files).

    DataAccess Providers in .NET

    ADO.NET comes with few providers, including:

  • OleDb
  • SqlClient
  • Microsoft made the SQL Server. So they gave a separate provider, specifically made for SQL Server. We can use the OleDb provider for all other database sources including MS Access, Oracle, Sybase etc. There is a separate provider available for Oracle.

    A DATA PROVIDER is a set of classes that can be used to access, retrieve and manipulate data from the databases.

    Both OleDb and SqlClient has its own set of classes, but they have the same concepts. We would like to classify the classes into two broad categories (this is not a microsoft classification, anyway!)

    Classes for communicate with database
    Classes for holding/manipulating data

    he job of first category of classes is to communicate with database and send or retrieve data from the database. The second category of the classes will be used as a carrier of data.

    Classes for communicating with database

    The Connection, Command, DataReader, and DataAdapter
    objects are the core elements of the ADO.NET provider model.

    Object Description SqlClient Objects OleDb Objects
    Connection Establishes a connection to a specific data source. SqlConnection OleDbConnection
    Command Executes a command against a data source. SqlCommand OleDbCommand
    DataReader Reads a forward-only, read-only stream of data from a data source. SqlDataReader OleDbDataReader
    DataAdapter Populates a DataSet and resolves updates with the data source. SqlDataAdapter OleDbDataAdapter


    Each provider may have classes equivalent to above objects. The name of the classes vary slightly to represent the provider type appropriately.

    Depending on the type of database you work on, you will have to choose either OleDb or SqlClient (or, some other provider) objects. Since all our samples use MS Access database, we will be using OleDb objects in all the samples. If you like to use SqlServer, you just need to replace the OleDb objects with the equivalent SqlClient objects.

    Classes for holding data

    The following are the main classes used to hold data in Ado.NET:

    DataSet
    DataTable
    DataRow

    A DataSet is an in-memory representation of the database.
    DataSet contains DataTables (and more...)
    DataTable represents a database table
    DataTable contains DataRows (and more...)
    A DataRow represents a record in a database table.
    DataRow is a collection of all fields in a record.

    We can use the DataAdapter or DataReader to populate data in DataSet. Once we populate data from database, we can loop through all Tables in the DataSet and through each record in each Table.
    Write your comment now