Working with database programming with the help of ADO.NET(active data objects for net)
Generally we can store the data at 2 locations data storage
1)RAM
2)hard-disk(perment memory)
In harddisk data store in two locations
1)Filehandling
2)databaseprogramming(ADO.NET)
Problems with filehandling while storing real-time data
1)columns information like column names and datatypes are not allowed
2)number of columns cannot be restricted
3)there is a possibility for data redundancy
4)it is difficult to handle data manipulations
5)there is no security for the data
To overcome all these problems ANSI introduced a concept called as database.
A collection of inter related data is called as a database. These databases are divided into 3 types
1)DBMS
Ex:dbase,fox base, foxpro, lotus123
2)RDBMS
Ex:oracle,sqlserver,Sybase,ms.access
3)ORDBMS
Ex:oracle 8i,sql server 2005
Working with ADO.NET
1)ADO.NET is an object library, which is use to communicate with any type of databases
2)ADO.NET is used to develop client-server architectures
3)ADO.NET supports 2 types of database connections
a)managed connection
b)unmanaged connection
4)managed connections are faster in data accessing
5)managed connections works with the help of TDS protocol(TDS->Tabullar data stream)
6)unmanaged connections works with the help of oledb providers(oledb->object linking and embedding data base)
7)oledb providers are predeveloped DLL files which are com components
8)As com is platform dependent, hence connections over oledb are unmanaged
9)There will be a unique provider name(predefined) for every database
Ex:for oracle, The provider name is msdaora1
For sqlserver, the provider name is sqloledb1
10)To work with ADO.NET, Microsoft introduced an assembly called as system.Data.Dll. with 9 sub-namespaces. These are divided into 5 groups
Group1:common namespaces for managed and unmanaged connections
1)system.data
2)system.data.common
3)system.data.sqltypes
Group2:namespaces for unmanaged connections
4)system.data.(supports all databases)
Group3:namespaces for managed connections
5)system.data.sqlclient(supports only sqlserver)
6)system.data.oracleclient(supports only oracle) but this is depreeated from .net 2010)
Group4:namespace for ODBC connections
7)system.data.odbc(supports all databases)
Group5:namespaces for language integrated query concepts
8)system.data.linq(supports only sqlserver)
9)system.data.linq.mapping
ADO.NET example:
A program to create a table in oracle
Open windows forms application project:
Start->programs->Microsoft visual studio 2010->Microsoft Visual studio 2010->file menu->new->
project->select visual c# from installed templates->select windows forms application project
place a button
using system.data.oledb;
code for button1-click
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsFormsApplication14
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OleDbConnection cn = new OleDbConnection("provider=msdaora.1;userid=scott;password=tiger");
try
{
cn.Open();
MessageBox.Show("a logical likein between oracle and .net is created");
string s = "create table emp244(eno number,ename varchar2(10),sal number)";
OleDbCommand cmd = new OleDbCommand(s, cn);
cmd.ExecuteNonQuery();
MessageBox.Show("table is created");
}
catch (Exception e1)
{
MessageBox.Show(e1.Message);
}
finally
{
cn.Close();
MessageBox.Show("conn is closed");
}
}
}
}
Execute the project F5
Note:Open oracle software, The check emp244 is created or not.
Select * from tab; …prints all the tablenames