SlideShare a Scribd company logo
1 of 9
Download to read offline
Asp.net – Database connectivity
How to connect an asp.net application with Database
ConnectionString
• The database connection information is stored in the web.config
file as a ConnectionString tag.
• Web.config is a xml file which is used to store application wide
settings and constants
• The ConnectionString has two main attributes
– Name – this holds a name for the connectionstring with which a
particular connectionstring is identified, useful when using multiple
databases
– ConnectionString – this holds the actual connection data
The ConnectionString attribute
Database Host User Id
Database name Password
Getting the connection information from within the application
The connection string added in the web.config can be obtained from
anywhere within the application using the following line of code
ConnectionString name as given in the web.config
For connecting to the database from an asp.net application we use
the following inbuilt classes of the .net framework
• sqlCommand object
• sqlConnection object
• sqlDataReader / sqlDataAdapter object
Creating and initializing the sqlCommand object
The following lines of code creates an sqlCommand object and initializes it
Name of the
stored
procedure
passed as an
argument
Setting the command type property
as stored procedure, the other
commandtypes are text(for inline
queries) and table direct
Setting the commandName property
to the passed in stored procedure
name
The above function takes the name of a stored procedure as parameter and
returns a sqlCommand object whose commandtype is set as stored procedure
and commandText is set as the name of the stored procedure
Interacting with the database
The following lines of code connects with the database and runs the query in the
commandText property of the sqlCommand object in the database
property of the sqlCommand object The sqlCommand object is
passed as an argument to
the function
sqlConnection object is
initialized with the data in
the connectionstring
sqlDataAdapter object is
initialized for the
sqlCommand object
Interacts with the
database and returns the
resulting dataset
A new dataset variable is
initialized for holding the
returning data from the
database (if any)
Interacting with the database
• sqlDataReader object can also be used to interact with the database but it
allows only one way communication, that is, read from the database, while
sqlDataAdapter object allows writing to as well as reading from the database
• The data read from the database is stored in the dataset object and returned
Retrieving data from the dataset object
A dataset object is a collection of datatable objects, datatables contain
datarows and columns just as it will appear in a database table
For eg. Suppose the dataset returned by a certain database interaction is as
follows
Id Name
10 Ab
11 cd
class Subject
v Maths
x English
Table 1 Table 2
ds
Retrieving data from the dataset object
• The data in the second column of the first row in table 1 can be
retrieved as
– ds.Tables(0).rows(0)(1) or ds.Tables(0).rows(0)(“Name”)
• Similarly the data in the second column of the second row in table
2 can be retrieved as
– ds.Tables(1).rows(1)(1) or ds.Tables(1).rows(1)(“Subject”)
Id Name
10 Ab
11 cd
class Subject
v Maths
x English
Table 1 Table 2
If this presentation helped you, please visit our
page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com

More Related Content

What's hot

Data management with ado
Data management with adoData management with ado
Data management with ado
Dinesh kumar
 

What's hot (20)

Introduction to oops concepts
Introduction to oops conceptsIntroduction to oops concepts
Introduction to oops concepts
 
Introduction To C#
Introduction To C#Introduction To C#
Introduction To C#
 
Relational model
Relational modelRelational model
Relational model
 
Database connectivity to sql server asp.net
Database connectivity to sql server asp.netDatabase connectivity to sql server asp.net
Database connectivity to sql server asp.net
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#
 
vb.net Constructor and destructor
vb.net Constructor and destructorvb.net Constructor and destructor
vb.net Constructor and destructor
 
VB.NET:An introduction to Namespaces in .NET framework
VB.NET:An introduction to  Namespaces in .NET frameworkVB.NET:An introduction to  Namespaces in .NET framework
VB.NET:An introduction to Namespaces in .NET framework
 
Ado.Net Tutorial
Ado.Net TutorialAdo.Net Tutorial
Ado.Net Tutorial
 
2 tier and 3 tier architecture
2 tier and 3 tier architecture2 tier and 3 tier architecture
2 tier and 3 tier architecture
 
C# Private assembly
C# Private assemblyC# Private assembly
C# Private assembly
 
Assemblies
AssembliesAssemblies
Assemblies
 
The Ultimate Sequence Diagram Tutorial
The Ultimate Sequence Diagram TutorialThe Ultimate Sequence Diagram Tutorial
The Ultimate Sequence Diagram Tutorial
 
Data management with ado
Data management with adoData management with ado
Data management with ado
 
Object oriented programming concepts
Object oriented programming conceptsObject oriented programming concepts
Object oriented programming concepts
 
Dbms relational model
Dbms relational modelDbms relational model
Dbms relational model
 
Databases: Normalisation
Databases: NormalisationDatabases: Normalisation
Databases: Normalisation
 
Python Modules
Python ModulesPython Modules
Python Modules
 
unit testing and debugging
unit testing and debuggingunit testing and debugging
unit testing and debugging
 
Pandas csv
Pandas csvPandas csv
Pandas csv
 

Viewers also liked

Easy database migrations with C# and FluentMigrator
Easy database migrations with C# and FluentMigratorEasy database migrations with C# and FluentMigrator
Easy database migrations with C# and FluentMigrator
Safal Mahat
 
Top 10 linux administrator interview questions and answers
Top 10 linux administrator interview questions and answersTop 10 linux administrator interview questions and answers
Top 10 linux administrator interview questions and answers
jomrida
 
Jayamohan_Linux_Administrator
Jayamohan_Linux_AdministratorJayamohan_Linux_Administrator
Jayamohan_Linux_Administrator
Jayamohan Nair
 
Explanation of behavior change project template
Explanation of behavior change project templateExplanation of behavior change project template
Explanation of behavior change project template
Maclf
 

Viewers also liked (19)

Easy database migrations with C# and FluentMigrator
Easy database migrations with C# and FluentMigratorEasy database migrations with C# and FluentMigrator
Easy database migrations with C# and FluentMigrator
 
Ado .net
Ado .netAdo .net
Ado .net
 
Top 10 linux administrator interview questions and answers
Top 10 linux administrator interview questions and answersTop 10 linux administrator interview questions and answers
Top 10 linux administrator interview questions and answers
 
GTU Asp.net Project Training Guidelines
GTU Asp.net Project Training GuidelinesGTU Asp.net Project Training Guidelines
GTU Asp.net Project Training Guidelines
 
Optimize Data Connectivity in .NET Applications
Optimize Data Connectivity in .NET ApplicationsOptimize Data Connectivity in .NET Applications
Optimize Data Connectivity in .NET Applications
 
Jayamohan_Linux_Administrator
Jayamohan_Linux_AdministratorJayamohan_Linux_Administrator
Jayamohan_Linux_Administrator
 
Drag and Drop Application Development with Progress Rollbase
Drag and Drop Application Development with Progress RollbaseDrag and Drop Application Development with Progress Rollbase
Drag and Drop Application Development with Progress Rollbase
 
3d password - Report
3d password - Report  3d password - Report
3d password - Report
 
3d password 23 mar 14
3d password 23 mar 143d password 23 mar 14
3d password 23 mar 14
 
3d password ppt
3d password ppt3d password ppt
3d password ppt
 
Project report
Project reportProject report
Project report
 
Developing an ASP.NET Web Application
Developing an ASP.NET Web ApplicationDeveloping an ASP.NET Web Application
Developing an ASP.NET Web Application
 
3d password by suresh
3d password by suresh3d password by suresh
3d password by suresh
 
Java CRUD Mechanism with SQL Server Database
Java CRUD Mechanism with SQL Server DatabaseJava CRUD Mechanism with SQL Server Database
Java CRUD Mechanism with SQL Server Database
 
Hadoop MapReduce Fundamentals
Hadoop MapReduce FundamentalsHadoop MapReduce Fundamentals
Hadoop MapReduce Fundamentals
 
Review Materi ASP.NET
Review Materi ASP.NETReview Materi ASP.NET
Review Materi ASP.NET
 
Explanation of behavior change project template
Explanation of behavior change project templateExplanation of behavior change project template
Explanation of behavior change project template
 
State of the Word 2011
State of the Word 2011State of the Word 2011
State of the Word 2011
 
How to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheHow to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your Niche
 

Similar to ASP.NET- database connectivity

Introduction to ado
Introduction to adoIntroduction to ado
Introduction to ado
Harman Bajwa
 
ASP.NET Session 11 12
ASP.NET Session 11 12ASP.NET Session 11 12
ASP.NET Session 11 12
Sisir Ghosh
 
Ado.net xml data serialization
Ado.net xml data serializationAdo.net xml data serialization
Ado.net xml data serialization
Raghu nath
 

Similar to ASP.NET- database connectivity (20)

Ado.net
Ado.netAdo.net
Ado.net
 
Unit4
Unit4Unit4
Unit4
 
Ado.net
Ado.netAdo.net
Ado.net
 
ADO.NET
ADO.NETADO.NET
ADO.NET
 
ADO.NET
ADO.NETADO.NET
ADO.NET
 
ADO.net control
ADO.net controlADO.net control
ADO.net control
 
Csharp_dotnet_ADO_Net_database_query.pptx
Csharp_dotnet_ADO_Net_database_query.pptxCsharp_dotnet_ADO_Net_database_query.pptx
Csharp_dotnet_ADO_Net_database_query.pptx
 
Introduction to ado
Introduction to adoIntroduction to ado
Introduction to ado
 
Introduction to ADO.NET
Introduction to ADO.NETIntroduction to ADO.NET
Introduction to ADO.NET
 
ADO .Net
ADO .Net ADO .Net
ADO .Net
 
Chap14 ado.net
Chap14 ado.netChap14 ado.net
Chap14 ado.net
 
Disconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NETDisconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NET
 
ADO.NET by ASP.NET Development Company in india
ADO.NET by ASP.NET  Development Company in indiaADO.NET by ASP.NET  Development Company in india
ADO.NET by ASP.NET Development Company in india
 
ASP.NET Session 11 12
ASP.NET Session 11 12ASP.NET Session 11 12
ASP.NET Session 11 12
 
ASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NETASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NET
 
Ado.net xml data serialization
Ado.net xml data serializationAdo.net xml data serialization
Ado.net xml data serialization
 
Chapter 3: ado.net
Chapter 3: ado.netChapter 3: ado.net
Chapter 3: ado.net
 
Ado.Net Architecture
Ado.Net ArchitectureAdo.Net Architecture
Ado.Net Architecture
 
VISUAL BASIC .net data accesss vii
VISUAL BASIC .net data accesss viiVISUAL BASIC .net data accesss vii
VISUAL BASIC .net data accesss vii
 
Ado.net with asp.net
Ado.net with asp.netAdo.net with asp.net
Ado.net with asp.net
 

More from baabtra.com - No. 1 supplier of quality freshers

More from baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

ASP.NET- database connectivity

  • 1. Asp.net – Database connectivity
  • 2. How to connect an asp.net application with Database ConnectionString • The database connection information is stored in the web.config file as a ConnectionString tag. • Web.config is a xml file which is used to store application wide settings and constants • The ConnectionString has two main attributes – Name – this holds a name for the connectionstring with which a particular connectionstring is identified, useful when using multiple databases – ConnectionString – this holds the actual connection data
  • 3. The ConnectionString attribute Database Host User Id Database name Password
  • 4. Getting the connection information from within the application The connection string added in the web.config can be obtained from anywhere within the application using the following line of code ConnectionString name as given in the web.config For connecting to the database from an asp.net application we use the following inbuilt classes of the .net framework • sqlCommand object • sqlConnection object • sqlDataReader / sqlDataAdapter object
  • 5. Creating and initializing the sqlCommand object The following lines of code creates an sqlCommand object and initializes it Name of the stored procedure passed as an argument Setting the command type property as stored procedure, the other commandtypes are text(for inline queries) and table direct Setting the commandName property to the passed in stored procedure name The above function takes the name of a stored procedure as parameter and returns a sqlCommand object whose commandtype is set as stored procedure and commandText is set as the name of the stored procedure
  • 6. Interacting with the database The following lines of code connects with the database and runs the query in the commandText property of the sqlCommand object in the database property of the sqlCommand object The sqlCommand object is passed as an argument to the function sqlConnection object is initialized with the data in the connectionstring sqlDataAdapter object is initialized for the sqlCommand object Interacts with the database and returns the resulting dataset A new dataset variable is initialized for holding the returning data from the database (if any)
  • 7. Interacting with the database • sqlDataReader object can also be used to interact with the database but it allows only one way communication, that is, read from the database, while sqlDataAdapter object allows writing to as well as reading from the database • The data read from the database is stored in the dataset object and returned Retrieving data from the dataset object A dataset object is a collection of datatable objects, datatables contain datarows and columns just as it will appear in a database table For eg. Suppose the dataset returned by a certain database interaction is as follows Id Name 10 Ab 11 cd class Subject v Maths x English Table 1 Table 2 ds
  • 8. Retrieving data from the dataset object • The data in the second column of the first row in table 1 can be retrieved as – ds.Tables(0).rows(0)(1) or ds.Tables(0).rows(0)(“Name”) • Similarly the data in the second column of the second row in table 2 can be retrieved as – ds.Tables(1).rows(1)(1) or ds.Tables(1).rows(1)(“Subject”) Id Name 10 Ab 11 cd class Subject v Maths x English Table 1 Table 2
  • 9. If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com