Step 1: Firstly open the Sql server and
create the database and table in it,The table must have a primary key for which
we can update and delete the data in gridview.

Step 2 : Now open the Visual Studio 2010 and click File->New->Web site->Select
the ASP.net website and then click ok.

Step 3: In The designing view add buttons,textboxes,gridview,labels as shown in
the following figure.

Step 4: Double click on the page and write the following code in it.
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Data;
using
System.Data.SqlClient;
public
partial class
Default2 : System.Web.UI.Page
{
SqlConnection con =
new SqlConnection("server=.;database=db;uid=sa;pwd=wintellect");
SqlDataAdapter da;
SqlCommand cmd;
DataSet ds = new
DataSet();
SqlDataReader dr;
protected void
Page_Load(object sender,
EventArgs e)
{
if (!IsPostBack)
{
show();
}
}
public void show()
{
da = new
SqlDataAdapter("select
* from employee", con);
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
Step 5: Double click on the insert button and write the following code in the
button click event.
protected
void Button1_Click(object
sender, EventArgs e)
{
string str = "insert into
employee values(@emp_id,@emp_name,@emp_salary)";
cmd = new
SqlCommand(str, con);
cmd.Parameters.AddWithValue("@emp_id",
TextBox1.Text);
cmd.Parameters.AddWithValue("@emp_name",
TextBox2.Text);
cmd.Parameters.AddWithValue("@emp_salary",
TextBox3.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
show();
Response.Write("Record Inserted");
}
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.


Rahul BazadPosted Sep 21, 2015, 2:26 AM
hello
surya mishraPosted Apr 24, 2013, 5:16 AM
I want to insert image in gridview plz help
surya mishraPosted Apr 24, 2013, 5:00 AM
Thanks sir This one really helpful for me.
aravind sandiPosted Oct 10, 2012, 6:47 AM
am getting error at insert cmd.executenonquery(); kindly solve my problem sir please.....
aravind sandiPosted Oct 10, 2012, 6:44 AM
insert cannot Working bro.....
aravind sandiPosted Oct 10, 2012, 6:44 AM
insert cannot Working bro.....
aravind sandiPosted Oct 10, 2012, 6:44 AM
insert cannot Working bro.....
aravind sandiPosted Oct 10, 2012, 6:44 AM
insert cannot Working bro.....
anil babuPosted Jun 26, 2012, 12:51 PM
Great post,give me same example cloud programming ....... pls