ADO.NET:-

Database programming with ADO.net:-  

  1. Generally, the output of the program will be stored in RAM.
  2. RAM is volatile, that is after every execution RAM memory will be cleared.
  3. To store the data permanently, .net is providing two ways

  • File handling
  • Database handling

 

Problems with File handling while storing real-time data:-

  101     teja             5000

102     raviteja         2000

102      Ravi              xyz

103       ravi             6000  

  1. The number of columns is not restricted.
  2. The type of data is not allowed.
  3. Possibility for data redundancy.
  4. Different to manipulate the data.
  5. No security for the data.

  Interested in mastering .NET? Learn more about ".NET Training" in this blog post.

  • To overcome these problems, ANSI introduced database concepts

  • A collection of interrelated data is called as databases are divided into three types

  Screenshot_13  

  • Create table EMP ( eno number, ename varchar 2 (10),…………..)
  • Create table XYZ

  ADO.NET (Active X Data objects for .net)  

  1. ADO.NET is an object library that is used to communicate with any database.
  2. Object library means a set of predefined class (a set of the namespace)
  3. ADO.NET is used to develop client Server Applications.

Screenshot_14

     C/S Architecture

  1. NET supports 2 types of connection

  Screenshot_15  

  1. Managed Connection
  2. Unmanaged Connection

 Managed connection:

Managed connections work with the help of the TDS  (Tabular data String) Protocol.  

Unmanaged Connection:

Unmanaged connections work with the help of OLEDB(object linking and Embedding   Databases ) provides.

  • OLEDB providers are DLL files, which are COM components As Com is platform-dependent, hence connection on OLEDB are called an Unmanaged connection.

Managed connections are faster in data accessing.

  Screenshot_16

  1. To work with ADO.net, Microsoft introduced System. Data Assembly, which contains 8  Namespaces.
  2. these Namespaces are divided into 5 Groups.

  Group 1:-

common namespace

  1. System. Data
  2. System.Data.Common

  1. System. Data. SQL Types 

  Group 2:-

Unmanaged Name Spaces 4.System. Data. OLEDB (Supports all type of databases)  

Group 3:-

Managed Namespaces

  1. System. Data. SQL client (SQL Server only)
  2. System. Data. oracle client (for oracle only ) (2.0)

  Group 4:-

ODBC Namespace

  1. System. Data. ODBC (supports all Databases)

  Group 5:-

LINQ Related Name Spaces

  1. System. Data. LINQ

Check Out .Net Tutorial

  EX 1:- With oracle over Unmanaged connection

  1. A program to create a table in oracle

Screenshot_17

A procedure to find provider names automatically.  

  1. Open notepad, save the file with the name

  “one. UDL” and close it File name        extension universal data Linker

  1. Double click on One .Udl file
  2. Select provider
  3. Choose “Micro-soft oledb provider for oracle ” and click Next
  4. Provide User name and password of oracle and click ok.
  5. Right-click on one.udl àopen with à note pad

 

  • Open WFAP
  • Place a button

  Using System. Data. Oledb;  

  • Code for Button 1 _click

    {

    Oledb connection con = new oledb connection

    (“User id = Scott ; password = tiger; provider = msdaora.1”);

    Con. open ();

    Message Box .show (“Connections is ok”);

    String q = “Create Table c 194 (Eno number, E name varchar 2 (10), Sql number)”;

    Oledb command cmd = new oledb command (q, con);

    Try {

    cmd. Execute Non query ()

    Message Box. Show (“Table is created ”);

    }

    Catch (oledb Exception oe)

    {

    Message Box. Show (oe. Message e );

    }

ADO.NET:-

Program to add records into c 194 table:-

Screenshot_18

Insert into c 194 value  (101, ‘Teja’, 5000)  

  • Open windows Forms Application Project
  • Design the form as shown Using System. Data . oledb
  • Code for Button 1_ click

String  s = “Insert in to c 194 values  (“ + text box1.Text  + “, ‘ “ + text box2. Text + “, ‘ “ + text box 3.text +”)”;

Message Box .show (s); Oledb _connection con = new loedb connection (“provider = ms da or a.1 ; user id = scott; password = tiger “);

Con. Open (); Oledb command cmd = new oledb command (s, con);

cmd. Execute Non query (); Message Box. Show (“Record is added”);

}