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

Lecture 01 introduction to database
Lecture 01 introduction to databaseLecture 01 introduction to database
Lecture 01 introduction to database
emailharmeet
 
All data models in dbms
All data models in dbmsAll data models in dbms
All data models in dbms
Naresh Kumar
 
3 Tier Architecture
3  Tier Architecture3  Tier Architecture
3 Tier Architecture
Webx
 
6. Integrity and Security in DBMS
6. Integrity and Security in DBMS6. Integrity and Security in DBMS
6. Integrity and Security in DBMS
koolkampus
 
Design patterns ppt
Design patterns pptDesign patterns ppt
Design patterns ppt
Aman Jain
 

What's hot (20)

Entity Relationship Diagram
Entity Relationship DiagramEntity Relationship Diagram
Entity Relationship Diagram
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
 
Functional dependency
Functional dependencyFunctional dependency
Functional dependency
 
Assemblies
AssembliesAssemblies
Assemblies
 
Database : Relational Data Model
Database : Relational Data ModelDatabase : Relational Data Model
Database : Relational Data Model
 
Ado.Net Tutorial
Ado.Net TutorialAdo.Net Tutorial
Ado.Net Tutorial
 
Software requirements specification
Software requirements specificationSoftware requirements specification
Software requirements specification
 
Asp.net file types
Asp.net file typesAsp.net file types
Asp.net file types
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Lecture 01 introduction to database
Lecture 01 introduction to databaseLecture 01 introduction to database
Lecture 01 introduction to database
 
Presentation on Database management system
Presentation on Database management systemPresentation on Database management system
Presentation on Database management system
 
All data models in dbms
All data models in dbmsAll data models in dbms
All data models in dbms
 
Relational model
Relational modelRelational model
Relational model
 
3 Tier Architecture
3  Tier Architecture3  Tier Architecture
3 Tier Architecture
 
6. Integrity and Security in DBMS
6. Integrity and Security in DBMS6. Integrity and Security in DBMS
6. Integrity and Security in DBMS
 
3 Level Architecture
3 Level Architecture3 Level Architecture
3 Level Architecture
 
Design patterns ppt
Design patterns pptDesign patterns ppt
Design patterns ppt
 
Introduction to Database
Introduction to DatabaseIntroduction to Database
Introduction to Database
 
Dbms architecture
Dbms architectureDbms architecture
Dbms architecture
 
Database management system Lecture 7 : Strong and weak entity sets
Database management system Lecture 7 : Strong and weak entity setsDatabase management system Lecture 7 : Strong and weak entity sets
Database management system Lecture 7 : Strong and weak entity sets
 

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 (20)

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
 
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
 
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
 
Lecture 6. ADO.NET Overview.
Lecture 6. ADO.NET Overview.Lecture 6. ADO.NET Overview.
Lecture 6. ADO.NET Overview.
 

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

Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 

Recently uploaded (20)

Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
THE BEST IPTV in GERMANY for 2024: IPTVreel
THE BEST IPTV in  GERMANY for 2024: IPTVreelTHE BEST IPTV in  GERMANY for 2024: IPTVreel
THE BEST IPTV in GERMANY for 2024: IPTVreel
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
 
Connecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAKConnecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAK
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 

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