SlideShare a Scribd company logo
Insert, update, delete and select using
asp.net c# code with ado.net objects.
Step 1:Create a web forms application
Step 2:Create a Database
After creating a new website, create a new database from server explorer of
visual studio or SQL server.
After creating a new database, let's add new data tables with columns.
To create tables just click on your database name go to tables folder, when you
choose to create a table it will ask you add columns. You can add your custom name
column names along with data type. (Data Type : For string data choose - varchar(50)
or above, for integer data choose - int)
Step 3:Adding connection string
First Right click on the database name then
click on the properties (Alt + Enter). Find the connection string then copy that
connection string
Once we have copied the connection string we have to go to our asp.net web site
solution explorer. Find the web.config file open that web.config file.
Replace the above connection string with your copied connection string.
Step 4:Add new aspx file to web project
Add new aspx file i.e. default.aspx file to the web project & then Drag and drop
a gridview to the page from the tool box then do the following as shown in
below.
i.e. Add - Edit Delete buttons from the command field and check on the auto
generate fields. Edit link is for to choose which record to edit and delete link is
for to delete the selected record.
Create a form to update and insert records into database from website as
shown above i.e. Name, Address and Salary then add one hidden field and two
submit buttons, name it.
Step 5:Displaying records using select statement
• We will be display the records on grid view. So let’s display the records using select
statement.
• First thing we need to open up a connection to a database. So let’s do that step by step
• In default.aspx.cs file import the SQL namespaces on top .
using System.Data
using System.Data.SqlClient;
• Now in a page load write the connection string and open up the sql connection as shown
below.
string conn = ""; conn = ConfigurationManager.ConnectionStrings["Conn"].ToString();
SqlConnection objsqlconn = new SqlConnection(conn); objsqlconn.Open();
• After opening up the sql connection, Let's write the Select statement in the sql command and
the execute the sql query using sql command execute reader and append it to grid view data
source as shown below.
objsqlconn.Open();
SqlCommand objcmd = new SqlCommand("Select * from Employee", objsqlconn);
grd_dataset.DataSource = objcmd.ExecuteReader(); grd_dataset.DataBind();
Application of Insert and select notes.ppt x
Step 6:Inserting a new record using Insert
Statement
To add new record to the database we
will use the following form that we have
created in our default.aspx file.
We will write insert statement in the button
click event. So double click on a button, a
button click event opens up.
First we need to open up the sql connection as
same as previously we did it for select
statement then in a sql command write the
following insert statement as shown below.
So just run the website by holding Ctrl + F5 and add input data in the text box finally
click on add new record button to add new record to the database.

More Related Content

PPT
Database Connection
DOCX
Grid view control
PPTX
76.pptx ajx ppt file for univercity of granted
PPTX
PPTX
PPTX
Grid Vew Control VB
PPTX
Grid View Control CS
PPT
Chapter12 (1)
Database Connection
Grid view control
76.pptx ajx ppt file for univercity of granted
Grid Vew Control VB
Grid View Control CS
Chapter12 (1)

Similar to Application of Insert and select notes.ppt x (20)

PPTX
Work with data in ASP.NET
DOCX
Simple ado program by visual studio
DOCX
Simple ado program by visual studio
PDF
Step by Step Asp.Net GridView Tutorials
PDF
ALL NEW OOP 2014
PDF
Database Programming With Visual Basic Net And Adonet Tips Tutorials And Code...
PDF
Part 3 binding navigator vb.net
DOC
Cis407 a ilab 4 web application development devry university
PPTX
DOCX
Add row in asp.net Gridview on button click using C# and vb.net
DOCX
Add row in asp.net Gridview on button click using C# and vb.net
PPS
VISUAL BASIC .net data accesss vii
PPTX
Database and Access Power Point
PPTX
Database and Access Power Point
PPTX
Database and Access Power Point
PPTX
Baileybatts bailey battsdatabasepowerpoint8
DOCX
Cis 407 i lab 4 of 7
PPTX
Priyank Goel PPT.pptx
PPTX
Dev-In-Town:Linq To Sql by Chan Ming Man
DOCX
Machine problems
Work with data in ASP.NET
Simple ado program by visual studio
Simple ado program by visual studio
Step by Step Asp.Net GridView Tutorials
ALL NEW OOP 2014
Database Programming With Visual Basic Net And Adonet Tips Tutorials And Code...
Part 3 binding navigator vb.net
Cis407 a ilab 4 web application development devry university
Add row in asp.net Gridview on button click using C# and vb.net
Add row in asp.net Gridview on button click using C# and vb.net
VISUAL BASIC .net data accesss vii
Database and Access Power Point
Database and Access Power Point
Database and Access Power Point
Baileybatts bailey battsdatabasepowerpoint8
Cis 407 i lab 4 of 7
Priyank Goel PPT.pptx
Dev-In-Town:Linq To Sql by Chan Ming Man
Machine problems
Ad

Recently uploaded (20)

PDF
RMMM.pdf make it easy to upload and study
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Computing-Curriculum for Schools in Ghana
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Cell Structure & Organelles in detailed.
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Classroom Observation Tools for Teachers
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Pre independence Education in Inndia.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Pharma ospi slides which help in ospi learning
PDF
Basic Mud Logging Guide for educational purpose
PPTX
Microbial diseases, their pathogenesis and prophylaxis
RMMM.pdf make it easy to upload and study
Module 4: Burden of Disease Tutorial Slides S2 2025
Computing-Curriculum for Schools in Ghana
O7-L3 Supply Chain Operations - ICLT Program
Microbial disease of the cardiovascular and lymphatic systems
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Cell Structure & Organelles in detailed.
PPH.pptx obstetrics and gynecology in nursing
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Classroom Observation Tools for Teachers
Renaissance Architecture: A Journey from Faith to Humanism
2.FourierTransform-ShortQuestionswithAnswers.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
VCE English Exam - Section C Student Revision Booklet
Pre independence Education in Inndia.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Complications of Minimal Access Surgery at WLH
Pharma ospi slides which help in ospi learning
Basic Mud Logging Guide for educational purpose
Microbial diseases, their pathogenesis and prophylaxis
Ad

Application of Insert and select notes.ppt x

  • 1. Insert, update, delete and select using asp.net c# code with ado.net objects.
  • 2. Step 1:Create a web forms application
  • 3. Step 2:Create a Database After creating a new website, create a new database from server explorer of visual studio or SQL server.
  • 4. After creating a new database, let's add new data tables with columns. To create tables just click on your database name go to tables folder, when you choose to create a table it will ask you add columns. You can add your custom name column names along with data type. (Data Type : For string data choose - varchar(50) or above, for integer data choose - int)
  • 5. Step 3:Adding connection string First Right click on the database name then click on the properties (Alt + Enter). Find the connection string then copy that connection string Once we have copied the connection string we have to go to our asp.net web site solution explorer. Find the web.config file open that web.config file.
  • 6. Replace the above connection string with your copied connection string.
  • 7. Step 4:Add new aspx file to web project Add new aspx file i.e. default.aspx file to the web project & then Drag and drop a gridview to the page from the tool box then do the following as shown in below. i.e. Add - Edit Delete buttons from the command field and check on the auto generate fields. Edit link is for to choose which record to edit and delete link is for to delete the selected record. Create a form to update and insert records into database from website as shown above i.e. Name, Address and Salary then add one hidden field and two submit buttons, name it.
  • 8. Step 5:Displaying records using select statement • We will be display the records on grid view. So let’s display the records using select statement. • First thing we need to open up a connection to a database. So let’s do that step by step • In default.aspx.cs file import the SQL namespaces on top . using System.Data using System.Data.SqlClient; • Now in a page load write the connection string and open up the sql connection as shown below. string conn = ""; conn = ConfigurationManager.ConnectionStrings["Conn"].ToString(); SqlConnection objsqlconn = new SqlConnection(conn); objsqlconn.Open(); • After opening up the sql connection, Let's write the Select statement in the sql command and the execute the sql query using sql command execute reader and append it to grid view data source as shown below. objsqlconn.Open(); SqlCommand objcmd = new SqlCommand("Select * from Employee", objsqlconn); grd_dataset.DataSource = objcmd.ExecuteReader(); grd_dataset.DataBind();
  • 10. Step 6:Inserting a new record using Insert Statement To add new record to the database we will use the following form that we have created in our default.aspx file. We will write insert statement in the button click event. So double click on a button, a button click event opens up. First we need to open up the sql connection as same as previously we did it for select statement then in a sql command write the following insert statement as shown below. So just run the website by holding Ctrl + F5 and add input data in the text box finally click on add new record button to add new record to the database.