Data access services are provided by ADO.net.. Ado .net is an object oriented component that allows interaction with data bases.
Disconnected data access architecture(Data setlocal buffer of persistence data, connecte to the database get the required data to a data set and disconnect from the database)
But also provide connection oriented data access.
Data set objects stores tables their relationships and constraints.. So the user can make updates to the dataset locally and may updated the database when needed.(reduces the network traffic and increase the performance)
Different components:
1.Data set local buffer of tables or a collection of disconnected record sets.
2.Data tableused to contain data in a tabular form, rows and columns
3. DataRowSingle record in a datarow
4.DataColumn fiels of a Data table.
5.Datarelationrepresent s differtent relationships between different table ina data set.
6.constraint represents different constraints and limitations that apply to a field or column
ADO .net contains some database specific classes
SYSTEM.DATA.SqlClient
General class
SYSTEM.DATA.OleDb (but database specific classes optimese the performance)
Steps of accessing a database using ADO.net
1. Defining the connection string for the database.
2.Defining the connectionusing the connection string
3.Defining the command string(command string that contains the query)
4.Defining the data adaptorusing the command string and the connection object.
5.Creating a new dataset object
6.1 if the command is a selection command filling the dataset object with the result of the query through the data adaptor
6.1.1 Reading the tables in the dataset using DataRow and Column Objects
6.2if the command is update delete insert, update the dataset through the data asapterCODE SAMPLE
Using Systm.data;
Using Syatem.data.sqlclient/oledb;
string connstring=”server=..;database=…;uid=..;pwd=..;”;
sqlConnection conn= new sqlconnection(connstring);
string command=”select * from …”;
sqlDataAdaptor dataAdaptor=new sqldataAdaptor(command,conn); //fills a dataset when executed
Dataset ds =new dataset();
//filling the results using a data adaptor
dataAdaptor.fill(ds,”prog”); // fill the data to ds store the data in a prog table
Datatable table=ds.Tables[“prog”]; //getting and referenc to the data table n the data set so tah we can access the data
String value=table.rows[0][attrname].tosrting();