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

Reflection and ADO. Net: Karthik Eetur

Uploaded by

Kartik Kashyap
Copyright
© Attribution Non-Commercial (BY-NC)
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)
54 views

Reflection and ADO. Net: Karthik Eetur

Uploaded by

Kartik Kashyap
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 38

Reflection and ADO.

Net

Karthik Eetur
REFLECTION
 Reflection is a way of getting information about any
specific class or assembly at runtime. You can also say
its RTTI (Runtime Type Information).
 With the help of reflection you can get the all the
properties and methods with arguments/parameters. You
can also get the list of classes, interfaces, structures and
enumeration in an assembly by using reflection.
 You can dynamically create an instance of an object at
runtime and invoke methods dynamically.
 examples of reflection: Object browser and Visual Studio
.NET IDE (Integrated Development Environment)
Namespace: System. Reflection

 The Reflection namespace contains


classes and interfaces that provide a
managed view of loaded types,
methods, and fields, with the ability to
dynamically create and invoke types.
Classes in Reflection
class AmbiguousMatchException The exception that is thrown when
binding to a method results in more
than one method matching the binding
criteria. 

class Assembly Defines an Assembly, which is a


reusable, versionable, and self-
describing building block of a common
language runtime application. 

class AssemblyAlgorithmIdAttribute Specifies an algorithm to hash all files


in an assembly. This class cannot be
inherited. 

class AssemblyCompanyAttribute Defines a company name custom


attribute for an assembly manifest. 
class AssemblyConfigurationAttribute Defines an assembly configuration
custom attribute (such as retail or debug)
for an assembly manifest. 

class AssemblyCopyrightAttribute Defines a copyright custom attribute for


an assembly manifest. 

class AssemblyCultureAttribute Specifies which culture the assembly


supports. 

class AssemblyDefaultAliasAttribute Defines a friendly default alias for an


assembly manifest. 

class AssemblyDelaySignAttribute Specifies that the assembly is not fully


signed when created. 

class AssemblyDescriptionAttribute Defines an assembly description custom


attribute for an assembly manifest. 
class AssemblyFlagsAttribute Specifies whether an assembly
supports side-by-side execution on the
same machine, in the same process, or
in the same application domain. This
class cannot be inherited. 

class AssemblyInformationalVersionAttr Defines an assembly informational


ibute version custom attribute for an
assembly manifest. 

class AssemblyKeyFileAttribute Specifies the name of a file containing


the key pair used to generate a shared
name. 
class AssemblyName Fully describes an assembly's unique
identity. 
class AssemblyNameProxy Provides a remotable version of the . 

class AssemblyProductAttribute Defines a product name custom


attribute for an assembly manifest. 
class ConstructorInfo Discovers the attributes of a class
constructor and provides access to
constructor metadata. 

class CustomAttributeFormatException The exception that is thrown when the


binary format of a custom attribute is
invalid. 

class DefaultMemberAttribute Defines the member of a type that is


the default member used by
Type.InvokeMember. The default
member is a name given to a type. 

class EventInfo Discovers the attributes of an event


and provides access to event
metadata. 
class FieldInfo Discovers the attributes of a field and
provides access to field metadata.
class ManifestResourceInfo Contains manifest resource topology
information. 
class MemberInfo Discovers the attributes of a member
and provides access to member
metadata. 

class MethodBase Provides information about methods


and constructors. 
class MethodInfo Discovers the attributes of a method
and provides access to method
metadata. 

class Missing Represents a missing Object. This


class cannot be inherited. 

class Module Performs reflection on a module. 


class ParameterInfo Discovers the attributes of a parameter
and provides access to parameter
metadata. 
class Pointer Provides a wrapper class for pointers. 

class PropertyInfo Discovers the attributes of a property


and provides access to property
metadata. 
class ReflectionTypeLoadException The exception that is thrown by the
Module.GetTypes method if any of the
classes in a module cannot be loaded.
This class cannot be inherited. 

class StrongNameKeyPair Encapsulates access to a public or


private key pair used to sign strong
name assemblies. 
class TargetException Represents the exception that is
thrown when an attempt is made to
invoke an invalid target. 
Interfaces & Structures in
Reflection
interface ICustomAttributeProvider Provides custom attributes for reflection
objects that support them. 

interface IReflect Allows objects to return MemberInfo


objects that represent an object. 

structure InterfaceMapping Retrieves the mapping of an interface


into the actual methods on a class that
implements that interface. 

structure ParameterModifier Attaches a modifier to parameters so


that binding can work with parameter
signatures in which the types have
been modified. 
(refer document)
Loading Metadata of an Assembly
 In the Entity Data Model (EDM), item collections are
responsible for loading metadata from persistent
resources, such as XML files or common language
runtime (CLR) assemblies, and are in an instance of the
MetadataWorkspace class
 ADO.NET provides an ItemCollection class as a core
API for loading and holding in-memory metadata.
 The ItemCollection has several derived classes, such
as ObjectItemCollection, EdmItemCollection,
StoreItemCollection, and StorageMappingItemCollection.
 Each of these collection classes is specialized for a
different type of metadata. The following sections explain
how these collection classes interact with different types
of metadata.
 ObjectItemCollection:

The ObjectItemCollection class is responsible for


loading metadata about the object model. The object
model represents the CLR classes that can be used as
a programmatic realization of the conceptual model.

 EdmItemCollection:

An EdmItemCollection class is responsible for


loading metadata about the conceptual model. The
EdmItemCollection class loads its metadata from a
conceptual schema definition language (CSDL) file
that is an XML representation of the conceptual model.
 StoreItemCollection:

An StoreItemCollection class is responsible for loading


the metadata about the storage (database) model. The
StoreItemCollection class loads its metadata from a store
schema definition language (SSDL) file that is an XML
representation of the storage model.

 StorageMappingItemCollection :

A StorageMappingItemCollection class is responsible for


loading metadata that represents the mapping between the
conceptual model and the storage (database) model.
The StorageMappingItemCollection class loads its
metadata from a mapping specification language (MSL) file
that is an XML representation of the mapping between the
conceptual model and the storage model.
ADO.NET

 ADO.NET is a set of classes that expose data


access services for .NET Framework programmers.
 ADO.NET provides a rich set of components for
creating distributed, data-sharing applications.
 It is an integral part of the .NET Framework,
providing access to relational, XML, and application
data.
 ADO.NET supports a variety of development needs,
including the creation of front-end database clients
and middle-tier business objects used by
applications, tools, languages, or Internet browsers.
ADO.NET OVERVIEW
 ADO.NET provides consistent access to data sources such as
SQL Server and XML, and to data sources exposed through OLE
DB and ODBC. Data-sharing consumer applications can use
ADO.NET to connect to these data sources and retrieve, handle,
and update the data that they contain.
 ADO.NET separates data access from data manipulation into
discrete components that can be used separately or in tandem.
 ADO.NET includes .NET Framework data providers for
connecting to a database, executing commands, and retrieving
results. Those results are either processed directly, placed in an
ADO.NET Dataset object in order to be exposed to the user in an
ad hoc manner, combined with data from multiple sources, or
passed between tiers.
 The Dataset object can also be used independently of a .NET
Framework data provider to manage data local to the application
or sourced from XML.
ADO.NET ARCHITECTURE
 Advantages of ADO. Net :
 ADO. Net works on disconnected architecture.
 data can be cached in datasets.
 data is persisted as XML.
 Performance : Extremely Fast.
 Disadvantages of ADO. Net:
 Providing a comprehensive disconnected data-
access model, which is crucial to the Web
environment
 Providing tight integration with XML, and
 Providing seamless integration with the .NET
Framework (e.g., compatibility with the base class
library's type system).
DAO & RDO in ADO
 Data Access Objects (DAO) can be used either with the Microsoft
Jet database engine or, using the ODBCDirect option, without it.
 This chapter discusses design and implementation issues that
arise when using the Data Access Objects (DAO) to access remote
databases.
 Remote Data Objects (RDO) implement a set of objects to deal
with the special requirements of remote data access.
 RDO implements a thin code layer over the ODBC API and driver
manager that establishes connections, creates result sets and
cursors, and executes complex procedures using minimal
workstation resources.
 Although RDO is also accessed by DAO when your code creates
an ODBCDirect Workspace object, documentation for this
implementation can be found by searching for specific
ODBCDirect topics.
Features of Remote Data Objects
 With RDO and the RemoteData control, your applications can access

ODBC data sources without using a local query processor

By using RDO, you can:

 Create simple cursorless result sets, or more complex cursors.

 Run queries and process any number of result sets.

 Execute stored procedures that return result sets with or without output parameters
and return values.

 Execute action queries that perform data manipulation or data definition operations.
Data Providers
.NET Framework data provider Description
.NET Framework Data Provider for For Microsoft® SQL Server™ version 7.0
SQL Server or later.
.NET Framework Data Provider for For data sources exposed using OLE
OLE DB DB.
.NET Framework Data Provider for For data sources exposed using ODBC.
ODBC Note   The .NET Framework Data
Provider for ODBC is not included in
the .NET Framework version 1.0. If you
require the .NET Framework Data
Provider for ODBC and are using the
.NET Framework version 1.0, you can
download the .NET Framework Data
Provider for ODBC at
http://msdn.microsoft.com/downloads.
The namespace for the downloaded
.NET Framework Data Provider for
ODBC is Microsoft.Data.Odbc.
.NET Framework Data Provider for For Oracle data sources. The .NET
Oracle Framework Data Provider for Oracle
supports Oracle client software version
8.1.7 and later. Note   The .NET
Framework Data Provider for Oracle is
not included in the .NET Framework
version 1.0. If you require the .NET
Framework Data Provider for Oracle
and are using the .NET Framework
version 1.0, you can download the .NET
Framework Data Provider for Oracle at
http://msdn.microsoft.com/downloads.
core elements of the .NET Framework
data provider model
Object Description

Connection Establishes a connection to a specific


data source.

Command Executes a command against a data


source.

DataReader Reads a forward-only, read-only


stream of data from a data source.

DataAdapter Populates a DataSet and resolves


updates with the data source.
Connection Class
 SqlConnection con = new
SqlConnection(@"Data Source=JLC-
A10ADD7FFE4\SQLEXPRESS;Initial
Catalog=srinivas;Integrated
Security=True");
 Here con is the connection class object
 Using connection class con we are
connecting to database using
connection string
Connection Strings
 A connection string contains initialization information
that is passed as a parameter from a data provider to
a data source.
 The syntax depends on the data provider, and the
connection string is parsed during the attempt to
open a connection.
 Syntax errors generate a run-time exception, but
other errors occur only after the data source receives
connection information.
 Once validated, the data source applies the options
specified in the connection string and opens the
connection.
Command class
 Initialization of object:
SqlCommand cmd;
Methods of SqlCommand class:
 ExecuteNonQuery()

used for INSERT,UPDATE,DELETE


 ExecuteScalar()

used to perform changes to single column


 ExecuteReader()

used for select statement


Using Commands to Modify Data (ADO.NET)

 Using a .NET Framework data provider, you can execute stored


procedures or data definition language statements (for example,
CREATE TABLE and ALTER COLUMN) to perform schema
manipulation on a database or catalog. These commands do not
return rows as a query would, so the Command object provides
an ExecuteNonQuery to process them.
 In addition to using ExecuteNonQuery to modify schema, you
can also use this method to process SQL statements that modify
data but that do not return rows, such as INSERT, UPDATE, and
DELETE.
 Although rows are not returned by the ExecuteNonQuery
method, input and output parameters and return values can be
passed and returned via the Parameters collection of the
Command object.
Data Reader and Data Adapters
 You can use the ADO.NET DataReader to retrieve a read-
only, forward-only stream of data from a database. Results
are returned as the query executes, and are stored in the
network buffer on the client until you request them using the
Read method of the DataReader. Using the DataReader
can increase application performance both by retrieving
data as soon as it is available, and (by default) storing only
one row at a time in memory, reducing system overhead.
 A DataAdapter is used to retrieve data from a data source
and populate tables within a DataSet. The DataAdapter also
resolves changes made to the DataSet back to the data
source. The DataAdapter uses the Connection object of
the .NET Framework data provider to connect to a data
source, and it uses Command objects to retrieve data from
and resolve changes to the data source.
Classes in .NET Data provider
Object Description
Transaction Enables you to enlist commands in
transactions at the data source.

CommandBuilder A helper object that will automatically


generate command properties of a
DataAdapter or will derive parameter
information from a stored procedure
and populate the Parameters
collection of a Command object.

Parameter Defines input, output, and return value


parameters for commands and stored
procedures.
Exception Returned when an error is
encountered at the data source. For
an error encountered at the client,
.NET Framework data providers throw
a .NET Framework exception.

Error Exposes the information from a


warning or error returned by a data
source.

ClientPermission Provided for .NET Framework data


provider code access security
attributes.
Transaction handling
 Begin Transaction
Some code to update records
Some code to select some records
Retrieve some data from the selected records
Update some value depending upon selected
records
 Commit Transaction
App.config file
 Windows applications in VS.NET use the name
app.config by default for the configuration file.
 This will not be automatically created when you
create a Windows application. If you need a
configuration file for your application, open your
project in VS.NET, go to the 'Solution Explorer' and
right click on the project name. Choose Add > Add
new item from the menu and select 'Application
Configuration file' from the list of choices. This will
create an app.config file for you in the application
root.
 By default, the app.config file will have the following
content:
Store values in config file
 <?xml version="1.0" encoding="utf-8" ?>
<configuration>

</configuration>
 To store values in the configuration file,
you can create XML elements in the
format:
<add key="MyKey" value="MyValue" />
 See the sample config entries below:
 <?xml version="1.0" encoding= "utf-8" ?>

<configuration>

<appSettings>

<add key="DatabasePath"
value="c:\\projects\data\spider.mdb" />

<add key="SupportEmail" value="webmaster-


1@dotnetspider.com" />

</appSettings>

</configuration>
Read values from config file
 To read from this config file, just use the
following code in your application:
 string dbPath =
System.Configuration.ConfigurationSetti
ngs.AppSettings["DatabasePath"];
 string email =
System.Configuration.ConfigurationSetti
ngs.AppSettings["SupportEmail"];
 ConfigurationSettings is the class used to
access the contents of the configuration file
 using System.Configuration;
 If you have the above directive on top of
file, we can use
 string dbPath =
ConfigurationSettings.AppSettings["Databa
sePath"];
string email =
ConfigurationSettings.AppSettings["Support
Email"];
 In VB.NET, you have to use "( ... )"
instead of the "[ ... ]", as shown below:
 Dim dbPath as String =
ConfigurationSettings.AppSettings("Dat
abasePath")
Dim email as String =
ConfigurationSettings.AppSettings("Sup
portEmail")
Thank you….

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy