SlideShare a Scribd company logo
1 of 18
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

Similar to Asp .Net Database Connectivity Presentation.pptx

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

Introduction to ado
Introduction to adoIntroduction to ado
Introduction to ado
 
Chapter 3: ado.net
Chapter 3: ado.netChapter 3: ado.net
Chapter 3: ado.net
 
Marmagna desai
Marmagna desaiMarmagna desai
Marmagna desai
 
Chapter 14
Chapter 14Chapter 14
Chapter 14
 
Datasource in asp.net
Datasource in asp.netDatasource in asp.net
Datasource in asp.net
 
ADO.NET
ADO.NETADO.NET
ADO.NET
 
Lecture 6. ADO.NET Overview.
Lecture 6. ADO.NET Overview.Lecture 6. ADO.NET Overview.
Lecture 6. ADO.NET Overview.
 
Ado.Net Architecture
Ado.Net ArchitectureAdo.Net Architecture
Ado.Net Architecture
 
ADO .Net
ADO .Net ADO .Net
ADO .Net
 
Ado.net
Ado.netAdo.net
Ado.net
 
WEB PROGRAMMING USING ASP.NET
WEB PROGRAMMING USING ASP.NETWEB PROGRAMMING USING ASP.NET
WEB PROGRAMMING USING ASP.NET
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
 
Data Access Technologies
Data Access TechnologiesData Access Technologies
Data Access Technologies
 
PPT temp.pptx
PPT temp.pptxPPT temp.pptx
PPT temp.pptx
 
ASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NETASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NET
 
Sql server 2012 tutorials writing transact-sql statements
Sql server 2012 tutorials   writing transact-sql statementsSql server 2012 tutorials   writing transact-sql statements
Sql server 2012 tutorials writing transact-sql statements
 
Introduction to SQLite in Adobe AIR
Introduction to SQLite in Adobe AIRIntroduction to SQLite in Adobe AIR
Introduction to SQLite in Adobe AIR
 
Chap14 ado.net
Chap14 ado.netChap14 ado.net
Chap14 ado.net
 
Jsp project module
Jsp project moduleJsp project module
Jsp project module
 

Recently uploaded

Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixingviprabot1
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 

Recently uploaded (20)

Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixing
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 

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