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

Sql queries presentation
Sql queries presentationSql queries presentation
Sql queries presentationNITISH KUMAR
 
Database design process
Database design processDatabase design process
Database design processTayyab Hameed
 
Data management with ado
Data management with adoData management with ado
Data management with adoDinesh kumar
 
Designing Techniques in Software Engineering
Designing Techniques in Software EngineeringDesigning Techniques in Software Engineering
Designing Techniques in Software Engineeringkirupasuchi1996
 
Fundamental design concepts
Fundamental design conceptsFundamental design concepts
Fundamental design conceptssrijavel
 
3 Level Architecture
3 Level Architecture3 Level Architecture
3 Level ArchitectureAdeel Rasheed
 
Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principlesdeonpmeyer
 
User controls
User controlsUser controls
User controlsaspnet123
 
Database systems
Database systemsDatabase systems
Database systemsDhani Ahmad
 
Normalisation - 2nd normal form
Normalisation - 2nd normal formNormalisation - 2nd normal form
Normalisation - 2nd normal formcollege
 
Query optimization in SQL
Query optimization in SQLQuery optimization in SQL
Query optimization in SQLAbdul Rehman
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)Dhani Ahmad
 
Chapter 3: ado.net
Chapter 3: ado.netChapter 3: ado.net
Chapter 3: ado.netNgeam Soly
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to databaseArpee Callejo
 
Type of database models
Type of database modelsType of database models
Type of database modelsSanthiNivas
 

What's hot (20)

Sql queries presentation
Sql queries presentationSql queries presentation
Sql queries presentation
 
Database design process
Database design processDatabase design process
Database design process
 
ADO .Net
ADO .Net ADO .Net
ADO .Net
 
Assemblies
AssembliesAssemblies
Assemblies
 
Data management with ado
Data management with adoData management with ado
Data management with ado
 
Designing Techniques in Software Engineering
Designing Techniques in Software EngineeringDesigning Techniques in Software Engineering
Designing Techniques in Software Engineering
 
Fundamental design concepts
Fundamental design conceptsFundamental design concepts
Fundamental design concepts
 
Data dictionary
Data dictionaryData dictionary
Data dictionary
 
3 Level Architecture
3 Level Architecture3 Level Architecture
3 Level Architecture
 
Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principles
 
User controls
User controlsUser controls
User controls
 
Database systems
Database systemsDatabase systems
Database systems
 
Normalisation - 2nd normal form
Normalisation - 2nd normal formNormalisation - 2nd normal form
Normalisation - 2nd normal form
 
Query optimization in SQL
Query optimization in SQLQuery optimization in SQL
Query optimization in SQL
 
Triggers and Stored Procedures
Triggers and Stored ProceduresTriggers and Stored Procedures
Triggers and Stored Procedures
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
 
Chapter 3: ado.net
Chapter 3: ado.netChapter 3: ado.net
Chapter 3: ado.net
 
Component based software engineering
Component based software engineeringComponent based software engineering
Component based software engineering
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
 
Type of database models
Type of database modelsType of database models
Type of database models
 

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 FluentMigratorSafal 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 answersjomrida
 
GTU Asp.net Project Training Guidelines
GTU Asp.net Project Training GuidelinesGTU Asp.net Project Training Guidelines
GTU Asp.net Project Training GuidelinesTOPS Technologies
 
Optimize Data Connectivity in .NET Applications
Optimize Data Connectivity in .NET ApplicationsOptimize Data Connectivity in .NET Applications
Optimize Data Connectivity in .NET ApplicationsAbhishek Kant
 
Jayamohan_Linux_Administrator
Jayamohan_Linux_AdministratorJayamohan_Linux_Administrator
Jayamohan_Linux_AdministratorJayamohan Nair
 
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 RollbaseAbhishek Kant
 
3d password 23 mar 14
3d password 23 mar 143d password 23 mar 14
3d password 23 mar 14Saddam Ahmed
 
Developing an ASP.NET Web Application
Developing an ASP.NET Web ApplicationDeveloping an ASP.NET Web Application
Developing an ASP.NET Web ApplicationRishi Kothari
 
3d password by suresh
3d password by suresh3d password by suresh
3d password by sureshsuresh5c2
 
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 DatabaseDudy Ali
 
Hadoop MapReduce Fundamentals
Hadoop MapReduce FundamentalsHadoop MapReduce Fundamentals
Hadoop MapReduce FundamentalsLynn Langit
 
Review Materi ASP.NET
Review Materi ASP.NETReview Materi ASP.NET
Review Materi ASP.NETDudy Ali
 
Explanation of behavior change project template
Explanation of behavior change project templateExplanation of behavior change project template
Explanation of behavior change project templateMaclf
 
State of the Word 2011
State of the Word 2011State of the Word 2011
State of the Word 2011photomatt
 
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 NicheLeslie Samuel
 

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

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.pptxfacebookrecovery1
 
Introduction to ado
Introduction to adoIntroduction to ado
Introduction to adoHarman Bajwa
 
Introduction to ADO.NET
Introduction to ADO.NETIntroduction to ADO.NET
Introduction to ADO.NETrchakra
 
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.NETEverywhere
 
ASP.NET Session 11 12
ASP.NET Session 11 12ASP.NET Session 11 12
ASP.NET Session 11 12Sisir Ghosh
 
Ado.net xml data serialization
Ado.net xml data serializationAdo.net xml data serialization
Ado.net xml data serializationRaghu nath
 
Ado.Net Architecture
Ado.Net ArchitectureAdo.Net Architecture
Ado.Net ArchitectureUmar Farooq
 
VISUAL BASIC .net data accesss vii
VISUAL BASIC .net data accesss viiVISUAL BASIC .net data accesss vii
VISUAL BASIC .net data accesss viiargusacademy
 
Ado.net with asp.net
Ado.net with asp.netAdo.net with asp.net
Ado.net with asp.netSireesh K
 
Lecture 6. ADO.NET Overview.
Lecture 6. ADO.NET Overview.Lecture 6. ADO.NET Overview.
Lecture 6. ADO.NET Overview.Alexey Furmanov
 

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
 
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.
 
2310 b 09
2310 b 092310 b 09
2310 b 09
 

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

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.pptxRustici Software
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
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.pptxRemote DBA Services
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
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, ...apidays
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
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 educationjfdjdjcjdnsjd
 
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...DianaGray10
 
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...Jeffrey Haguewood
 

Recently uploaded (20)

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
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
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
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
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...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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, ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
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
 
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...
 
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...
 

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