-------------------------------------------------------------------------------------------
Prepared By : Uday Shah (HOD
– IT)
Contact No : 7600044051
E-Mail :
rupareleducation@gmail.com
C# Unit 4 : Data Base Programming with ADO.NET
Q-1 What
is ADO.NET?
·
Most application requires
some form of data access.
·
ADO.NET is a part
of Microsoft .net framework.
·
The full form of
ADO.NET is active data object.
·
ADO.NET has the
ability to separate data access mechanisms data manipulation and data
connectivity mechanisms.
·
ADO.NET is a set
of classes that allow application to read and write information in database.
·
Following is a diagram of ADO.NET activity:-
Following is a diagram of ADO.NET activity:-
·
According to
above diagram.
·
ADO.NET can be
used by any .NET languages.
·
ADO.NET is
concept it’s not a programming language.
·
ADO.NET
introduces the concept of disconnected architecture.
·
To use ADO.NET we
need to add system. Data namespace.
·
It is next version of active data object
technology which is used in V.B 6.0.
·
To work with
database we need to add a namespace that is……
Using system.data.sqlclient
Q-2 what
is disconnected environment? Or
Explain
connected and disconnected architecture.
·
The ADO.NET framework
supports two model of data access architecture.
·
That is……
1) Connection oriented data access architecture
2) Disconnected data access architecture.
·
In connection
oriented data access architecture application make a connection to the data
source and then interact with sql request using the same connection.
·
In this case the
application stay connected to throw database system even when it is not using
by any database operation.
·
ADO.NET solve
this problem by introduce a new concept of local buffering of, persistence data
using data set.
·
The data set is
central component in the ADO.NET disconnected a data access architecture.
·
A database is an
in memory data store that can hold multiple tables at the same time.
·
Dataset only hold
data and do not interact with data source.
·
One of the key
character rustics of data set is that it has no knowledge of the underline data
source.
·
That night have
been used to populate it.
·
To create a
dataset object use following syntax:-
Dataset ds = new dataset ( );
·
According to
above syntax:-
·
Dataset represent
ether an entire database or a subset of database.
·
It contains
tables and relationship between those tables.
Connected
architecture :
1. Command:
·
It is used to
fire sql commands or perform some action on the data source.
·
Such as ……
Insert, update and delete.
·
Command object is
depending on connection object.
·
Command object
are use to execute command to a database across a data connection.
·
The command
object in ADO.NET execute sql statements and store procedures that return
single value one or more set of rows or No value at all.
·
The command
object has a property called command text which contain a string value that
represent the command that will be executed in the data source.
·
Command object
require minimum two things.
·
That is ……
Connection and query.
·
There are four
overloaded constructor.
2. Data
Reader:-
·
When we execute
command object using execute reader () method at that time it return data
reader.
·
Which represent
forward and read only rewards?
·
Data reader is
use to restive read only and for word only stream of the data from the
database.
·
It means we
cannot perform any insert update or delete operation in data reader.
·
Data reader is
opposite of dataset
·
We cannot move
previous in data reader.
·
When we just want
to the data use data reader fill.
·
Data reader
requires open connection.
·
Data reader can
hold one table at a time.
·
Data reader has
item collection.
·
Data reader has
read method to read next recode.
Disconnected
Architecture :
1. Data adepter:-
·
It is associated
with command and connection object.
·
The data adepter is the class at the core of
ADO.NET disconnected data access.
·
It is the bridge
between dataset and the database.
·
The data adepter
provide a set of methods and properties to retrieve and saves data between
dataset ant databases.
·
The data adepter
is used fill method to fill a data table or dataset.
·
The data adepter
can commit the change to database by its update method
·
Data adepter
provide four properties that represent database command like,
·
Select, insert,
update and delete commands etc…
·
When the data
adepter fill a dataset it will create the necessary table and column for the
return data.
·
It has four
overloaded constructor.
2. Data table:-
·
Dataset contain a
collection of one or more data table object.
·
Data table can be
identifying in the dataset using dataset table property.
3. Data row:-
·
Data row
represent a row of data in data table.
·
You can add data
to the data table using data row object.
·
Data row
collection object represent a collection of data row of a data table.
·
Data row class
has its own properties and method. For access data base value.
4. Data
column:-
·
Data column is
one part of the data row.
·
Using a dataset
we can access an individual column and a value of the column from data row
using data column object.
5. Data
relation:-
·
Using a data relation
we can create parent child relationship between data tables.
·
ADO.NET data
table object maintain a collection of constrain like, primary key, reference
key, unique key, not null etc……
·
Using a data
relation object we can element redundant data with the help of join
queries.
6. Data view:-
·
Data view work
with data table.
·
Every table has a
default data view.
·
With the help of
data view you can create different views of the data store in data table.
·
Data view has a
list of properties and methods.
·
Using data view
you can expose the data in table with different shorted order and filter data.
·
Data view
provides a dynamic view of single set of data.
·
Data view has
important properties like, short and row filter.
·
Data view does
not affect the actual data store in data table.
Q.3 ADO.NET
Data Providers
The classes responsible for the movement of data
between the disconnected data classes in the client application and the data
store are referred to as connected classes or provider classes.
The ADO.NET Framework comes with the following
providers:
·
OLEDB: The
OLEDB provider, expressed through the System.Data.OleDb namespace.
You can use this provider to access SQL Server 6.5 and earlier, SyBase,
DB2/400, and Microsoft Access.
·
ODBC: The
ODBC provider, expressed through the System.Data.Odbc namespace. This
provider is typically used when no newer provider is available.
·
SQL
Server: The Microsoft SQL Server provider, expressed through
theSystem.Data.SqlClient namespace. It Contains classes that provide
functionality similar to the generic OleDb provider. The difference
is that these classes are tuned for SQL Server 7 and later data access.
Q-4 Command objects method.
·
Command object
has three important methods for execute queries.
·
To execute any
method it need to open a connection.
·
That for…….
1) Executescalar() method
2) Executenonquery() method
3) Executereader() method
·
Execute scalar it
is used with agree get function.
·
Agreegaet
functions are…….
1) Avg
2) Max
3) Min
4) Sum
5) Count
·
It returns one
value at a time.
·
It fetch data
from database
Executenonquery
Method:
·
It is use to fire
insert, update and delete queries to the database.
·
It returns
numbers of row affected it mean if we delete five records than it return five.
·
It is generally
use in connected architecture.
ExecuteReader
Method:
·
The DataReader
object is a forward-only and read-only cursor.
·
It requires a
live connection to the Data Source.
·
The DataReader
object cannot be directly instantiated. Instead, we must call the ExecuteReader
() Method of the command object to obtain a valid DataReader object.
ExecuteScalar
Method:
·
The ExecuteScalar
Method in SqlCommandObject returns the fist column of the first row after
executing the query against the Data Source.
·
If the result set
contain more than one column or rows, it takes only the first column of the
first row. All other values are ignored.
·
If the result set
is empty it will return a null.
Q.5 Data Binding
Windows
Forms allow you to bind easily to nearly any structure that contains data. With
data binding, you do not need to explicitly write the code that instantiates a
connection and creates a dataset On the basis of the number of bound values
that can be displayed through a control of a windows form, binding can be
classified into:
- Simple data binding
- Complex data binding
Simple
data binding
Simple
data binding allows you to bind a control to a single data element. The most
common use of simple data binding involves binding a single data element, such
as the value of a column in a table, to a control on a form. You use this type
of data binding for controls that show only one value. Uses of simple data
binding include binding data to text boxes and labels.
Complex Data Binding
Complex data binding allows you to bind more than one data element to a control. Using the column example, complex data binding involves binding more than one column or row from the underlying record source. Controls that support complex data binding include data grid controls, combo boxes, and list boxes.
Q-6 Explain Grid view.
·
It displays data
in grid control.
·
It means record
display in row and column tabular format.
·
Grid view display
record in standard format. Even we can format the row with background color.
·
It allows displaying
string, data, time, number etc…….
·
Data grid view
allow you to display structure data in static format as well as data from the
database
·
When we bind the
control to data source we can base on the structure of data source.
·
The grid view
control can display data in three distinct methods.
·
That is …….
1) Bound
2) Unbound
3) Virtual
:: Best Of Luck ::
Please share and comment it... Thank you.