SlideShare a Scribd company logo
3
Most read
15
Most read
16
Most read
ASP .Net Database Connectivity
Presenter: Sridhar Udayakumar
Outlines
● Introduction to Database
● What Is SQL?
● Working with Data in the .NET Framework
● ADO.Net
A Database
● A database is a collection of data that is
organized in a manner that facilitates ease of
access, as well as efficient management and
updating.
● A database is made up of tables that store
relevant information.
● For example, you would use a database, if you
were to create a website like YouTube, which
contains a lot of information like videos,
usernames, passwords, comments.
What is SQL?
● SQL stands for Structured Query Language.
● SQL is used to storing, manipulating and retrieving
relational database data.
● MySQL is a program that understands SQL.
● SQL can:
● insert, update, or delete records in a database.
● create new databases, table, stored procedures,
views.
● retrieve data from a database, etc.
SQL is an ANSI (American National Standards
Institute) standard, but there are different
versions of the SQL language.
Working with Data in the
.NET Framework
Approach to connect DB
ASP .Net framework and database can be interconnected
in 2 different approaches.
• ADO.NET
• Using any ORM (Entity Framework, NHibernate etc.)
ADO .Net
• Database connectivity and functionality are defined
in the ADO.NET namespaces of the .NET Framework.
• ADO.NET comes with several data providers,
including SqlClient, OleDB, and ODBC.
• .NET framework also provides in-memory data access
using LINQ. In this article
• SQL data provider of ADO.NET is defined in the
System.Data.SqlClient namespace
System.Data.SqlClient
• System.Data.SqlClient namespace of .NET Framework
contains all of the classes required to connect to
a SQL Server database and read, write, and update.
• The namespace provides classes to create a database
connection, adapters, and SQL commands that provide
the functionality to execute SQL queries.
Steps to connect database using ADO.Net
1. Declaring connectionStrings in web.config file
2. Establish the Connection
a. Get connection string from web.config file
b. create new SqlConnection object to connect
database by using connection string from
web.config file
c. Open the connection
3. Perform CRUD operation
4. Close the connection
Declaring connectionStrings
Add the below connection string configuration in web.config file
<connectionStrings>
<add name="yourconnectinstringName" connectionString="Data
Source= DatabaseServerName; Integrated Security=true;Initial
Catalog= YourDatabaseName; uid=YourUserName;
Password=yourpassword; "
providerName="System.Data.SqlClient" />
</connectionStrings>
Example:
<connectionStrings>
<add name="EmployeeDbConn" connectionString="Data
Source=INBOOK_X1_SLIMSQLEXPRESS;Initial
Catalog=EmploeeDb;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
Establish the Connection
//Get connection string from web.config file
string strcon =
ConfigurationManager.ConnectionStrings["dbconnection"].Conne
ctionString;
//create new sqlconnection and connection to database by
using connection string from web.config file
SqlConnection con = new SqlConnection(strcon);
//Open the Connection
con.Open();
PERFORM CRUD OPERATION
Executing the Commands
– Once connected to the database, you can execute
the set of commands that you're having and which
would execute on the server (or the data
provider) to execute the function you're trying
to do, such as a query for data, insert the
data, update records and so on and so forth.
SqlCommand command = new SqlCommand("SELECT * FROM
TableName", conn);
Parameterizing the data
• Parameterizing the query is done using the
SqlParameter ed into the command. For example, you
might want to search for the records where the
criteria match.
• You can denote that criterion by @ the variable
name into the query and then adding the value to it
using the SqlParameter object
// Create the command
SqlCommand command = new SqlCommand("SELECT * FROM TableName
WHERE FirstColumn = @0", conn);
// Add the parameters.
command.Parameters.Add(new SqlParameter("0", 1));
Reading the data returned
• In SQL, you usually use the SELECT statement to get
the data from the database to show.
• The class SqlDataReader present for the
SqlCommand that returns the Reader object for the
data. You can use this to read through the data and
for each of the columns, provide the results on the
screen.
Reading the data returned
string sql = "select * from employee";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
employeeList.Add(new Employee()
{
EmployeeId = (int)reader["employeeId"],
employeeName = reader["EmployeeName"].ToString(),
age = (int)reader["age"]
});
}
Close the Connection
Close the connection object once the CRUD operations CRUD is
completed
conn.Close();
THANK YOU

More Related Content

PPTX
REST API
PDF
Java Design Patterns Tutorial | Edureka
PPTX
DT-08-Hashing.PPTX
PDF
PDF
REST API Basics
PPTX
An Overview of Web Services: SOAP and REST
PDF
Unsafe JAX-RS: Breaking REST API
PDF
Learn REST in 18 Slides
REST API
Java Design Patterns Tutorial | Edureka
DT-08-Hashing.PPTX
REST API Basics
An Overview of Web Services: SOAP and REST
Unsafe JAX-RS: Breaking REST API
Learn REST in 18 Slides

What's hot (19)

PDF
GraphQL vs REST
PPT
Java Programming for Designers
PPTX
Adapter Design Pattern
PPS
Database Design Slide 1
PPT
Chapter06.ppt
PPTX
Data dictionary
PDF
Apache Kafka in the Healthcare Industry
PPTX
Best practices for RESTful web service design
PPTX
Servlet and jsp interview questions
PPTX
JAVA AWT
PPTX
Understanding REST APIs in 5 Simple Steps
PPTX
Adapter Design Pattern
PPTX
Kafka and Avro with Confluent Schema Registry
PDF
Spring Framework - MVC
PDF
REST vs. GraphQL: Critical Look
PPTX
Http session (Java)
PPT
Web servers
PPT
Java Server Faces (JSF) - Basics
PPTX
Electronic Records and Signatures
GraphQL vs REST
Java Programming for Designers
Adapter Design Pattern
Database Design Slide 1
Chapter06.ppt
Data dictionary
Apache Kafka in the Healthcare Industry
Best practices for RESTful web service design
Servlet and jsp interview questions
JAVA AWT
Understanding REST APIs in 5 Simple Steps
Adapter Design Pattern
Kafka and Avro with Confluent Schema Registry
Spring Framework - MVC
REST vs. GraphQL: Critical Look
Http session (Java)
Web servers
Java Server Faces (JSF) - Basics
Electronic Records and Signatures
Ad

Similar to Asp .Net Database Connectivity Presentation.pptx (20)

PPT
For Beginers - ADO.Net
PDF
Presentation on the ADO.NET framework in C#
PPTX
ADO.NET by ASP.NET Development Company in india
PPT
PPTX
111111112222223333335555555666Unit-4.pptx
PPTX
Ch06 ado.net fundamentals
PPT
ADO.net control
PPT
Ado.net
PPT
Synapseindia dot net development chapter 8 asp dot net
PPT
ASP.NET Session 11 12
PPTX
ADO architecture of XML andd Windows form
PPT
Introduction to ado
PDF
04. SQL Servesdafr with CSharp WinForms.pdf
PPTX
Chapter 3: ado.net
PPT
Marmagna desai
PDF
ADO.NET Interview Questions PDF By ScholarHat
PPTX
PPTX
Datasource in asp.net
PDF
Advanced database lab oracle structure query language
PPSX
ADO.NET
For Beginers - ADO.Net
Presentation on the ADO.NET framework in C#
ADO.NET by ASP.NET Development Company in india
111111112222223333335555555666Unit-4.pptx
Ch06 ado.net fundamentals
ADO.net control
Ado.net
Synapseindia dot net development chapter 8 asp dot net
ASP.NET Session 11 12
ADO architecture of XML andd Windows form
Introduction to ado
04. SQL Servesdafr with CSharp WinForms.pdf
Chapter 3: ado.net
Marmagna desai
ADO.NET Interview Questions PDF By ScholarHat
Datasource in asp.net
Advanced database lab oracle structure query language
ADO.NET
Ad

Recently uploaded (20)

PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
additive manufacturing of ss316l using mig welding
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
Well-logging-methods_new................
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
Welding lecture in detail for understanding
PPT
Mechanical Engineering MATERIALS Selection
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
CH1 Production IntroductoryConcepts.pptx
R24 SURVEYING LAB MANUAL for civil enggi
additive manufacturing of ss316l using mig welding
Model Code of Practice - Construction Work - 21102022 .pdf
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Well-logging-methods_new................
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Welding lecture in detail for understanding
Mechanical Engineering MATERIALS Selection
Operating System & Kernel Study Guide-1 - converted.pdf
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
UNIT-1 - COAL BASED THERMAL POWER PLANTS
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx

Asp .Net Database Connectivity Presentation.pptx

  • 1. ASP .Net Database Connectivity Presenter: Sridhar Udayakumar
  • 2. Outlines ● Introduction to Database ● What Is SQL? ● Working with Data in the .NET Framework ● ADO.Net
  • 3. A Database ● A database is a collection of data that is organized in a manner that facilitates ease of access, as well as efficient management and updating. ● A database is made up of tables that store relevant information. ● For example, you would use a database, if you were to create a website like YouTube, which contains a lot of information like videos, usernames, passwords, comments.
  • 4. What is SQL? ● SQL stands for Structured Query Language. ● SQL is used to storing, manipulating and retrieving relational database data. ● MySQL is a program that understands SQL. ● SQL can: ● insert, update, or delete records in a database. ● create new databases, table, stored procedures, views. ● retrieve data from a database, etc. SQL is an ANSI (American National Standards Institute) standard, but there are different versions of the SQL language.
  • 5. Working with Data in the .NET Framework
  • 6. Approach to connect DB ASP .Net framework and database can be interconnected in 2 different approaches. • ADO.NET • Using any ORM (Entity Framework, NHibernate etc.)
  • 7. ADO .Net • Database connectivity and functionality are defined in the ADO.NET namespaces of the .NET Framework. • ADO.NET comes with several data providers, including SqlClient, OleDB, and ODBC. • .NET framework also provides in-memory data access using LINQ. In this article • SQL data provider of ADO.NET is defined in the System.Data.SqlClient namespace
  • 8. System.Data.SqlClient • System.Data.SqlClient namespace of .NET Framework contains all of the classes required to connect to a SQL Server database and read, write, and update. • The namespace provides classes to create a database connection, adapters, and SQL commands that provide the functionality to execute SQL queries.
  • 9. Steps to connect database using ADO.Net 1. Declaring connectionStrings in web.config file 2. Establish the Connection a. Get connection string from web.config file b. create new SqlConnection object to connect database by using connection string from web.config file c. Open the connection 3. Perform CRUD operation 4. Close the connection
  • 10. Declaring connectionStrings Add the below connection string configuration in web.config file <connectionStrings> <add name="yourconnectinstringName" connectionString="Data Source= DatabaseServerName; Integrated Security=true;Initial Catalog= YourDatabaseName; uid=YourUserName; Password=yourpassword; " providerName="System.Data.SqlClient" /> </connectionStrings> Example: <connectionStrings> <add name="EmployeeDbConn" connectionString="Data Source=INBOOK_X1_SLIMSQLEXPRESS;Initial Catalog=EmploeeDb;Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings>
  • 11. Establish the Connection //Get connection string from web.config file string strcon = ConfigurationManager.ConnectionStrings["dbconnection"].Conne ctionString; //create new sqlconnection and connection to database by using connection string from web.config file SqlConnection con = new SqlConnection(strcon); //Open the Connection con.Open();
  • 13. Executing the Commands – Once connected to the database, you can execute the set of commands that you're having and which would execute on the server (or the data provider) to execute the function you're trying to do, such as a query for data, insert the data, update records and so on and so forth. SqlCommand command = new SqlCommand("SELECT * FROM TableName", conn);
  • 14. Parameterizing the data • Parameterizing the query is done using the SqlParameter ed into the command. For example, you might want to search for the records where the criteria match. • You can denote that criterion by @ the variable name into the query and then adding the value to it using the SqlParameter object // Create the command SqlCommand command = new SqlCommand("SELECT * FROM TableName WHERE FirstColumn = @0", conn); // Add the parameters. command.Parameters.Add(new SqlParameter("0", 1));
  • 15. Reading the data returned • In SQL, you usually use the SELECT statement to get the data from the database to show. • The class SqlDataReader present for the SqlCommand that returns the Reader object for the data. You can use this to read through the data and for each of the columns, provide the results on the screen.
  • 16. Reading the data returned string sql = "select * from employee"; SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { employeeList.Add(new Employee() { EmployeeId = (int)reader["employeeId"], employeeName = reader["EmployeeName"].ToString(), age = (int)reader["age"] }); }
  • 17. Close the Connection Close the connection object once the CRUD operations CRUD is completed conn.Close();