0% found this document useful (0 votes)
14 views57 pages

UNIT4

The document outlines the syllabus for a .Net course, focusing on ADO.NET, its components, and related concepts such as DataSet, DataTable, and DataRow classes. It also covers file uploading in ASP.NET, constructors, destructors, abstraction, interfaces, and polymorphism in C#. Additionally, it describes database access and the ADO.NET object model, including data providers and connection classes.

Uploaded by

Tech Coder
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views57 pages

UNIT4

The document outlines the syllabus for a .Net course, focusing on ADO.NET, its components, and related concepts such as DataSet, DataTable, and DataRow classes. It also covers file uploading in ASP.NET, constructors, destructors, abstraction, interfaces, and polymorphism in C#. Additionally, it describes database access and the ADO.NET object model, including data providers and connection classes.

Uploaded by

Tech Coder
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 57

.

Net

Prepared by:
Sumit Chhillar
(Assistant Professor)
SYLLABUS
UNIT IV

Basic window control; Architecture of ADO .Net; Comparison


with ADO; .Net Data provider; Data Adapter; Data Set; Data
Row; Data Column ; Data Relation; command; Data Reader;
Data Grid Constructor; Destructor; Abstraction;
interface ;polymorphism (Over loading and over ridding),
Data Access with Server Explorer.
ADO.NET

• ADO.NET provides a bridge between the front


end controls and the back end database. The
ADO.NET objects encapsulate all the data
access operations and the controls interact with
these objects to display data, thus hiding the
details of movement of data.
DataSet Class

• The dataset represents a subset of the database.


It does not have a continuous connection to the
database. To update the database a
reconnection is required. The DataSet contains
DataTable objects and DataRelation objects.
The DataRelation objects represent the
relationship between two tables.
DataSet Class

• CaseSensitive Indicates whether string comparisons within the data tables are case-
sensitive.
• Container Gets the container for the component.
• DataSetName Gets or sets the name of the current data set.
• DefaultViewManager Returns a view of data in the data set.
• DesignMode Indicates whether the component is currently in design mode.
• EnforceConstraints Indicates whether constraint rules are followed when
attempting any update operation.
• Events Gets the list of event handlers that are attached to this component.
• ExtendedProperties Gets the collection of customized user information associated
with the DataSet.
• HasErrors Indicates if there are any errors.
• IsInitialized Indicates whether the DataSet is initialized.
• LocaleGets or sets the locale information used to compare strings within the table.
• Namespace Gets or sets the namespace of the
DataSet.
• PrefixGets or sets an XML prefix that aliases
the namespace of the DataSet.
• Relations Returns the collection of
DataRelation objects.
• TablesReturns the collection of DataTable
objects.
DataTable Class

• The DataTable class represents the tables in


the database. It has the following important
properties; most of these properties are read
only properties except the PrimaryKey
property:
• ChildRelations Returns the collection of child relationship.
• ColumnsReturns the Columns collection.
• ConstraintsReturns the Constraints collection.
• DataSetReturns the parent DataSet.
• DefaultViewReturns a view of the table.
• ParentRelationsReturns the ParentRelations collection.
• PrimaryKeyGets or sets an array of columns as the primary
key for the table.
• RowsReturns the Rows collection.
DataTable Class

• some important methods of the DataTable class:


• AcceptChanges Commits all changes since the last AcceptChanges.
• Clear Clears all data from the table.
• GetChanges Returns a copy of the DataTable with all changes made since the
AcceptChanges method was called.
• GetErrors Returns an array of rows with errors.
• ImportRows Copies a new row into the table.
• LoadDataRow Finds and updates a specific row, or creates a new one, if not found
any.
• Merge Merges the table with another DataTable.
• NewRow Creates a new DataRow.
• Reject Changes Rolls back all changes made since the last call to AcceptChanges.
• Reset Resets the table to its original state.
• Select Returns an array of DataRow objects.
DataRow Class

• The DataRow object represents a row in a


table. It has the following important
properties:
• HasErrors Indicates if there are any errors.
• ItemsGets or sets the data stored in a specific
column.
• ItemArraysGets or sets all the values for the
row.
• TableReturns the parent table.
some important methods
of the DataRow class:
• AcceptChanges Accepts all changes made since this method was called.
• BeginEdit Begins edit operation.
• CancelEdit Cancels edit operation.
• Delete Deletes the DataRow.
• EndEdit Ends the edit operation.
• GetChildRows Gets the child rows of this row.
• GetParentRow Gets the parent row.
• GetParentRows Gets parent rows of DataRow object.
• RejectChanges Rolls back all changes made since the last call to
AcceptChanges.
The DataAdapter Object

• The DataAdapter object acts as a mediator


between the DataSet object and the database.
This helps the Dataset to contain data from
multiple databases or other data source.
The DataReader Object

• The DataReader object is an alternative to the


DataSet and DataAdapter combination. This
object provides a connection oriented access to
the data records in the database. These objects
are suitable for read-only access, such as
populating a list and then breaking the
connection.
DbCommand and
DbConnection Objects
• The DbConnection object represents a
connection to the data source. The connection
could be shared among different command
objects.
• The DbCommand object represents the
command or a stored procedure sent to the
database from retrieving or manipulating data.
ASP.NET - File
Uploading
• ASP.NET has two controls that allow users to upload files to the web
server. Once the server receives the posted file data, the application can
save it, check it, or ignore it. The following controls allow the file
uploading:
• HtmlInputFile - an HTML server control
• FileUpload - and ASP.NET web control
• Both controls allow file uploading, but the FileUpload control
automatically sets the encoding of the form, whereas the HtmlInputFile
does not do so.
• Once, the user has entered the filename in the text box by typing the name
or browsing, the SaveAs method of the FileUpload control can be called to
save the file to the disk.
The basic syntax of
FileUpload is:
• <asp:FileUpload ID= "Uploader" runat =
"server" />
• The FileUpload class is derived from the
WebControl class, and inherits all its members.
Apart from those, the FileUpload class has the
following read-only properties:
FileUpload Properties

• FileBytes Returns an array of the bytes in a file to be


uploaded.
• FileContent Returns the stream object pointing to the
file to be uploaded.
• FileName Returns the name of the file to be
uploaded.
• HasFile Specifies whether the control has a file to
upload.
• PostedFile Returns a reference to the uploaded file.
Example

• The following example demonstrates the FileUpload control and its properties. The
form has a FileUpload control along with a save button and a label control for
displaying the file name, file type, and file length.
• In the design view, the form looks as follows:
Constructors

• Constructors are a particular type of method


that is associated with a class and gets
automatically invoked when the classes
instance (i.e., objects) are created. Like other
member functions, i.e., methods, these
constructors also contain specific instructions
that get executed when the objects are created.
It is specifically used to assign values to all or
some data members of a class.
Characteristics of the
Constructor:
• The name of the constructors must have to be the same as that
of the name of the class in which will resides.
• A constructor can never be final, abstract, synchronized, and
static.
• You can produce only a single static constructor.
• A static constructor cannot be used as a parameterized
constructor.
• Constructors usually don't have a return type, not even void.
• The number of constructors can be any within a class.
• Constructors can contain access modifiers along with it.
Types of constructors
• Default Constructor: When constructors do not have
parameters, then it is called the default constructor. These
types of constructors have all its instance initialized with the
same value.
• Parameterized Constructor: When any constructor has at least
one parameter, then it is called the parameterized constructor.
• Copy Constructor: When the constructor is used to create an
object just by copying all of its variables from another object,
such constructors are called copy constructor. They are used
for initializing a new instance from an existing one.
• Private Constructor: When a constructor is produced
with a private access modifier, it is called Private
Constructor. It does not make it possible for other
classes to inherit any data from this class.
• Static Constructor: When a constructor needs to be
invoked only once and when that constructor needs to
be invoked at the creation of the first reference, and
then those constructors are made static and are called
static constructors.
Destructor

• Destructor is another method that uses the


class-name but is preceded with a ~ (tilde)
operator/symbol. Destructors are used to de-
initialize object, and the memories occupied
when constructors are created. You can
consider them as the opposite of constructors.
abstraction in C#

• Abstraction and encapsulation are related features in object-


oriented programming. Abstraction allows making relevant
information visible and encapsulation enables a programmer
to implement the desired level of abstraction.
• Abstraction can be achieved using abstract classes in C#. C#
allows you to create abstract classes that are used to provide a
partial class implementation of an interface. Implementation is
completed when a derived class inherits from it. Abstract
classes contain abstract methods, which are implemented by
the derived class. The derived classes have more specialized
functionality.
following are some of
the key points −
• You cannot create an instance of an abstract
class
• You cannot declare an abstract method outside
an abstract class
• When a class is declared sealed, it cannot be
inherited, abstract classes cannot be declared
sealed.
program
C# - Interfaces

• An interface is defined as a syntactical contract that all the classes


inheriting the interface should follow. The interface defines
the 'what' part of the syntactical contract and the deriving classes
define the 'how' part of the syntactical contract.
• Interfaces define properties, methods, and events, which are the
members of the interface. Interfaces contain only the declaration of
the members. It is the responsibility of the deriving class to define
the members. It often helps in providing a standard structure that the
deriving classes would follow.
• Abstract classes to some extent serve the same purpose, however,
they are mostly used when only few methods are to be declared by
the base class and the deriving class implements the functionalities.
Declaring Interfaces

• Interfaces are declared using the interface


keyword. It is similar to class declaration.
Interface statements are public by default.
Following is an example of an interface
declaration −
• public interface ITransactions {
• // interface members
• void showTransaction();
• double getAmount(); }
C# - Polymorphism

• The word polymorphism means having many


forms. In object-oriented programming
paradigm, polymorphism is often expressed as
'one interface, multiple functions'.
• Polymorphism can be static or dynamic.
In static polymorphism, the response to a
function is determined at the compile time.
In dynamic polymorphism, it is decided at
run-time.
Static Polymorphism

• The mechanism of linking a function with an


object during compile time is called early
binding. It is also called static binding. C#
provides two techniques to implement static
polymorphism. They are −
• Function overloading
• Operator overloading
Function Overloading

• You can have multiple definitions for the same


function name in the same scope. The
definition of the function must differ from
each other by the types and/or the number of
arguments in the argument list. You cannot
overload function declarations that differ only
by return type.
Dynamic Polymorphism

• C# allows you to create abstract classes that are used to provide


partial class implementation of an interface. Implementation is
completed when a derived class inherits from it. Abstract classes
contain abstract methods, which are implemented by the derived
class. The derived classes have more specialized functionality.
• Here are the rules about abstract classes −
• You cannot create an instance of an abstract class
• You cannot declare an abstract method outside an abstract class
• When a class is declared sealed, it cannot be inherited, abstract
classes cannot be declared sealed.
C# - Operator
Overloading
• You can redefine or overload most of the built-
in operators available in C#. Thus a
programmer can use operators with user-
defined types as well. Overloaded operators
are functions with special names the
keyword operator followed by the symbol for
the operator being defined. similar to any other
function, an overloaded operator has a return
type and a parameter list.
Overloadable and Non-
Overloadable Operators
• 1+, -, !, ~, ++, --
• These unary operators take one operand and can be overloaded.
• 2+, -, *, /, %
• These binary operators take one operand and can be overloaded.
• 3==, !=, <, >, <=, >=
• The comparison operators can be overloaded.
• 4&&, ||
• The conditional logical operators cannot be overloaded directly.
• 5+=, -=, *=, /=, %=
• The assignment operators cannot be overloaded.
• 6=, ., ?:, ->, new, is, sizeof, typeof
• These operators cannot be overloaded.
Database Access

• Applications communicate with a database,


firstly, to retrieve the data stored there and
present it in a user-friendly way, and secondly,
to update the database by inserting, modifying
and deleting data.
• Microsoft ActiveX Data Objects.Net
(ADO.Net) is a model, a part of the .Net
framework that is used by the .Net applications
for retrieving, accessing and updating data.
ADO.Net Object Model

• ADO.Net object model is nothing but the structured process flow through
various components. The object model can be pictorially described as −
• The data residing in a data store or database is
retrieved through the data provider. Various
components of the data provider retrieve data for the
application and update data.
• An application accesses data either through a dataset
or a data reader.
• Datasets store data in a disconnected cache and the
application retrieves data from it.
• Data readers provide data to the application in a
read-only and forward-only mode.
Data Provider

• A data provider is used for connecting to a


database, executing commands and retrieving
data, storing it in a dataset, reading the
retrieved data and updating the database.
• The data provider in ADO.Net consists of the
following four objects −
• 1Connection
• This component is used to set up a connection with a data source.
• 2Command
• A command is a SQL statement or a stored procedure used to retrieve,
insert, delete or modify data in a data source.
• 3DataReader
• Data reader is used to retrieve data from a data source in a read-only and
forward-only mode.
• 4DataAdapter
• This is integral to the working of ADO.Net since data is transferred to and
from a database through a data adapter. It retrieves data from a database
into a dataset and updates the database. When changes are made to the
dataset, the changes in the database are actually done by the data adapter.
different types of data providers
included in ADO.Net

• The .Net Framework data provider for SQL Server - provides


access to Microsoft SQL Server.
• The .Net Framework data provider for OLE DB - provides
access to data sources exposed by using OLE DB.
• The .Net Framework data provider for ODBC - provides
access to data sources exposed by ODBC.
• The .Net Framework data provider for Oracle - provides
access to Oracle data source.
• The EntityClient provider - enables accessing data through
Entity Data Model (EDM) applications.
Connecting to a Database

• The .Net Framework provides two types of


Connection classes −
• SqlConnection − designed for connecting to
Microsoft SQL Server.
• OleDbConnection − designed for connecting
to a wide range of databases, like Microsoft
Access and Oracle.
Example

• We have a table stored in Microsoft SQL


Server, named Customers, in a database named
testDB. Please consult 'SQL Server' tutorial for
creating databases and database tables in SQL
Server.
• Let us connect to this database. Take the
following steps −
• Select TOOLS → Connect to Database
• Select a server name and the database name in
the Add Connection dialog box.
• M
• Click on the Test Connection button to check if the connection succeeded.
Add a DataGridView on
the form.
• Click on the Choose Data Source combo box.
• Click on the Add Project Data Source link.
• This opens the Data Source Configuration Wizard.
• Select Database as the data source type
Choose DataSet as the
database model.
Choose the connection
already set up.
Save the connection
string.
• Choose the database object, Customers table in
our example, and click the Finish button.
• Select the Preview Data link to see the data in
the Results grid −
• When the application is run using Start button
available at the Microsoft Visual Studio tool
bar, it will show the following window −

You might also like