0% found this document useful (0 votes)
8 views

Dot Net 5

Dot net

Uploaded by

Siddhi Sonawane
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Dot Net 5

Dot net

Uploaded by

Siddhi Sonawane
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Dot net Lesson no 5.

1.ADO.NET
• The .NET Framework includes its own data access technology i.e.
ADO.NET
• ADO.NET is a set of classes that expose data access services for .NET
Framework programmers
• It is an integral part of the NET Framework
• ADO.NET provides a rich set of components for creating distributed and
data-sharing applications
• It provides access to relational, XML, and application data.
• ADO.NET is the latest implementation of (MDUA) Microsoft's Universal
Data Access strategy
2. Connection Object
• The Connection object is the first component of ADO.NET
• A Connection object sits between a data source and a DataAdapter (via
Command)
• You need to define a data provider and a data source when you create a
connection
• The Connection Object is a part of ADO.NET Data Provider and it is a
unique session with the Data Source
• In .Net Framework the Connection Object is Handling the part of
physical communication between the application and the Data Source. (
• ADO.NET Connection Object connects to the specified Database and
open a connection between the application and the Database.
• When the connection is established, SQL Commands may be executed,
with the help of the Connection Object to retrieve or manipulate data in
the Database.
• Once the Database activity is over, Connection should be closed and
releases the resources.
3.Command object
• The Command Object in ADO.NET executes SQL statements and Stored
Procedures against the data source specified in the Connection Object
• The Command Object required an instance of a Connection Object for
executing the SQL statements.
• The Command Object has a property called CommandText, which
contains a String value that represents the command that will be
executed in the Data Source.
• When the CommandType property is set to Stored Procedure, the
CommandText property should be set to the name of the stored
procedure.
4. methods uses in the Command Object to execute the SQL statements.
1. ExecuteNonQuery
2. ExecuteReader
3. ExecuteScalar
5.ADO.NET DataSet
• It is a collection of data tables that contain the data.
• it is used to fetch data without interacting with a Data Source that's why,
it also known as disconnected data access method.
• It is an in-memory data store that can hold more than one table at the
same time
• The DataSet can also be used to read and write data as XML document.
• ADO.NET provides a DataSet class that can be used to create DataSet
object
• It contains constructors and methods to perform data related operations

6.ADO.NET DataTable
• ADO.NET DataTable objects are used to represent the tables in a
DataSet.
• A DataTable represents one table of in-memory relational data
• The DataTable class is a member of the System.
• You can create and use a DataTable independently or as a member of a
DataSet
• DataTable objects can also be used in conjunction with other
• You access the collection of tables in a DataSet through the Tables
property of the DataSet object
• a table is represented by columns and constraints.
• a DataTable must also have rows to contain and order data.
• The DataRow class represents the actual data contained in a table
• You use the DataRow and its properties and methods to retrieve,
evaluate, and manipulate the data in a table.
• You create a relationship between DataTable objects using a Data
Relation.

7. Data table class properties


1. Row: represents all the row of the data table
2. Columns: represents all table columns
3. Constraints: represent all table constraints
4. Data set: represented data set for the table
5. Datafault view: customised view for the data
8.DataReader in ADO.NET
• There are two common objects in ADO.NET to read data, DataSet and
DataReader.
• A data reader provides an easy way for the programmer to read data
from a database.
• The DataReader is the solution for forward streaming data through
ADO.NET
• The data reader is also called a firehose cursor or forward read-only
cursor because it moves forward through the data.
• The data reader not only allows you to move forward through each
record of database, but it also enables you to parse the data from each
column
• The DataReader class represents a data reader in ADO.NET.
9. DataAdapter Object
• DataAdapter is a part of the ADO.NET Data Provider.
• DataAdapter provides the communication between the Dataset and the
Datasource
• We can use the DataAdapter in combination with the DataSet Object
• DataAdapter provides this combination by mapping Fill method, which
changes the data in the DataSet to match the data in the data source,
and Update, which changes the data in the data source to match the
data in the DataSet
• The DataAdapter can perform Select, Insert, Update and Delete SQL
operations in the Data Source.

10.Data Source Views


• Data source views are objects of the DataSourceView class.
• It represent a customized view of data for different data operations such
as sorting, filtering etc.
• The DataSourceView class serves as the base class for all data source
view classes, which define the capabilities of data source controls.

11. properties of the DataSourceView class:


1. CanDelete: Indicates whether deletion is allowed on the underlying data
source.
2. CanInsert: Indicates whether insertion is allowed on the underlying data
source.
3. CanPage: Indicates whether paging is allowed on the underlying data
source
4. CanSort: Indicates whether the data could be sorted.
5. CanUpdate: Indicates whether updates are allowed on the underlying
data sources
6. Name: Name of the view.

12. Explain class in ADO.NET


• Important Classes in ADO.NET
1. Connection Class
2. Command Class
3. DataReader Class
4. DataAdaptor Class
5. DataSet.Class
1. Connection Class: In ADO.NET, we use these connection classes to connect
to the database. These connection classes also manage transactions and
connection pooling.
2. Command Class: The Command class provides methods for storing and
executing SQL statements and Stored Procedures. The following are the
various commands that are executed by the Command Class.
2.1 ExecuteReader: Returns data to the client as rows. This would typically be
an SQL select statement or a Stored Procedure that contains one or more
select statements. This method returns a DataReader object that can be used
to fill a DataTable object or used directly for printing reports and so forth.
2.2 ExecuteNonQuery: Executes a command that changes the data in the
database, such as an update, delete, or insert statement, or a Stored
Procedure that contains one or more of these statements. This method returns
an integer that is the number of rows affected by the query.
2.3 ExecuteScalar: This method only returns a single value. This kind of query
returns a count of rows or a calculated value.
2.4 ExecuteXMLReader: (SqlClient classes only) Obtains data from an SQL
Server 2000 database using an XML stream. Returns an XML Reader object.
3. DataReader Class: The DataReader is used to retrieve data. It is used in
conjunction with the Command class to execute an SQL Select statement and
then access the returned rows.
4. DataAdapter Class: The DataAdapter is used to connect DataSets to
databases. The DataAdapter is most useful when using data-bound controls in
Windows Forms, but it can also be used to provide an easy way to manage the
connection between your application and the underlying database tables,
views and Stored Procedures.
5. DataSet Class: The DataSet is the heart of ADO.NET. The DataSet is
essentially a collection of DataTable objects. In turn each object contains a
collection of DataColumn and DataRow objects. The DataSet also contains a
Relations collection that can be used to define relations among Data Table
Objects.
13. How to Connect to a Database using ADO.NET?
• To create a connection, you must be familiar with connection strings
• A connection string is required as a parameter to SQLConnection.
• A ConnectionString is a string variable (not case sensitive). Liike provider,
server, database, userid and word as in the following:
Server="nameof the server or IP Address of the server
Database="name of the database"
userid="user name who has permission to work with database"
word="the word of userid"
• Example
SQL Authentication
String constr="server=.;database institute;
user id-rakesh;word-abc@123";

14.How to retrieve and display data from a database?


1. Create a SqlConnection object using a connection string.
2. Handle exceptions.
3. Open the connection.
4. Create a SQLCommand. To represent a SQLCommand like (select * from
studentdetails) and attach the existing connection to it.
5. Execute the command (use executereader).
6-Get the Result (use SqlDataReader). This is a forwardonly/readonly
dataobject
7. Close the connection
8. Process the result
9. Display the Result

You might also like