Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 6 > C# 6 General Discussion
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# 6 General Discussion Discussions about the C# 6 language and tools not related to any specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 6 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 7th, 2016, 10:47 AM
Registered User
Points: 9, Level: 1
Points: 9, Level: 1 Points: 9, Level: 1 Points: 9, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2016
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to Insert, Delete, Update in GridView in ASP.Net using C#

Hi guys

I am learing asp.net programming please help me i want to insert ,delete,update in asp.net grid view using c#.

thanks
Reply With Quote
  #2 (permalink)  
Old July 8th, 2016, 04:17 AM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default insert, delete, update in gridView in asp.net using C#

Hi Check this artciles.I hope it will solve your problem.

http://www.onlinebuff.com/article_st...adonet_32.html

https://www.mindstick.com/Articles/9...-using-c-sharp


http://www.aspneto.com/add-insert-ed...-net-c-vb.html
Reply With Quote
  #3 (permalink)  
Old July 14th, 2016, 05:21 AM
katieswift
Guest
 
Posts: n/a
Default

Delete:
protected void GridViewSample_RowDeleting(object sender, GridViewDeleteEventArgs e)

{

Label CustID = (Label)GridViewSample.Rows[e.RowIndex].FindControl("lblCustID");

using (SqlConnection Sqlcon = new SqlConnection(strCon))

{

using (SqlCommand cmd = new SqlCommand())

{

Sqlcon.Open();

cmd.Connection = Sqlcon;

cmd.CommandType = CommandType.StoredProcedure;

cmd.CommandText = "SP_Customer";

cmd.Parameters.Add(new SqlParameter("@pvchCustId", SqlDbType.Int));

cmd.Parameters.Add(new SqlParameter("@pvchAction", SqlDbType.VarChar, 50));

cmd.Parameters.Add(new SqlParameter("@pvchCreatedBy", SqlDbType.VarChar, 50));

cmd.Parameters.Add("@pIntErrDescOut", SqlDbType.Int).Direction = ParameterDirection.Output;

cmd.Parameters["@pvchAction"].Value = "delete";

cmd.Parameters["@pvchCustId"].Value = Convert.ToInt32(CustID.Text.ToString());

cmd.Parameters["@pvchCreatedBy"].Value = "Admin";

cmd.ExecuteNonQuery();

int retVal = (int)cmd.Parameters["@pIntErrDescOut"].Value;

}

}

GridViewSample.EditIndex = -1;

LoadData();

lblMessage.Text = "Record deleted successfully!";

}

insert:
protected void GridViewSample_RowCommand(object sender, GridViewCommandEventArgs e)

{

if (e.CommandName.Equals("Insert"))

{

int retVal=0;

TextBox Name = (TextBox)GridViewSample.FooterRow.FindControl("txt AddCustName");

TextBox Address1 = (TextBox)GridViewSample.FooterRow.FindControl("txt AddCustAdres1");

TextBox Address2 = (TextBox)GridViewSample.FooterRow.FindControl("txt AddCustAdres2");

TextBox Phone = (TextBox)GridViewSample.FooterRow.FindControl("txt AddCustPhone");

TextBox Email = (TextBox)GridViewSample.FooterRow.FindControl("txt AddEmail");

using (SqlConnection Sqlcon = new SqlConnection(strCon))

{

using (SqlCommand cmd = new SqlCommand())

{

Sqlcon.Open();

cmd.Connection = Sqlcon;

cmd.CommandType = CommandType.StoredProcedure;

cmd.CommandText = "SP_Customer";

cmd.Parameters.Add(new SqlParameter("@pvchAction", SqlDbType.VarChar, 50));

cmd.Parameters.Add(new SqlParameter("@pvchCustName", SqlDbType.VarChar, 100));

cmd.Parameters.Add(new SqlParameter("@pvchustaddress1", SqlDbType.VarChar, 100));

cmd.Parameters.Add(new SqlParameter("@pvchustaddress2", SqlDbType.VarChar, 100));

cmd.Parameters.Add(new SqlParameter("@pvchCustPhone", SqlDbType.VarChar, 100));

cmd.Parameters.Add(new SqlParameter("@pvchCustEmail", SqlDbType.VarChar, 100));

cmd.Parameters.Add(new SqlParameter("@pvchCreatedBy", SqlDbType.VarChar, 100));

cmd.Parameters.Add("@pIntErrDescOut", SqlDbType.Int).Direction = ParameterDirection.Output;

cmd.Parameters["@pvchAction"].Value = "insert";

cmd.Parameters["@pvchCustName"].Value = Name.Text.Trim();

cmd.Parameters["@pvchustaddress1"].Value = Address1.Text.Trim();

cmd.Parameters["@pvchustaddress2"].Value = Address2.Text.Trim();

cmd.Parameters["@pvchCustPhone"].Value = Phone.Text.Trim();

cmd.Parameters["@pvchCustEmail"].Value = Email.Text.Trim();

cmd.Parameters["@pvchCreatedBy"].Value = "Admin";

cmd.ExecuteNonQuery();

retVal = (int)cmd.Parameters["@pIntErrDescOut"].Value;

}

}

if (retVal == 2)

{

lblMessage.Text = "Customer name or Email ID aready exist!";

}

else

{

GridViewSample.EditIndex = -1;

LoadData();

lblMessage.Text = "Record inserted successfully!";

}

}

}

update:
protected void GridViewSample_RowEditing(object sender, GridViewEditEventArgs e)

{

GridViewSample.EditIndex = e.NewEditIndex;

LoadData();

}

protected void GridViewSample_RowUpdating(object sender, GridViewUpdateEventArgs e)

{

Label Custid = (Label)GridViewSample.Rows[e.RowIndex].FindControl("lblCustID");

TextBox Name = (TextBox)GridViewSample.Rows[e.RowIndex].FindControl("txtCustName");

TextBox Address1 = (TextBox)GridViewSample.Rows[e.RowIndex].FindControl("txtCustAddres1");

TextBox Address2 = (TextBox)GridViewSample.Rows[e.RowIndex].FindControl("txtCustAddres2");

TextBox Phone = (TextBox)GridViewSample.Rows[e.RowIndex].FindControl("txtCustPhone");

TextBox Email = (TextBox)GridViewSample.Rows[e.RowIndex].FindControl("txtEmail");

using (SqlConnection Sqlcon = new SqlConnection(strCon))

{

using (SqlCommand cmd = new SqlCommand())

{

Sqlcon.Open();

cmd.Connection = Sqlcon;

cmd.CommandType = CommandType.StoredProcedure;

cmd.CommandText = "SP_Customer";

cmd.Parameters.Add(new SqlParameter("@pvchAction", SqlDbType.VarChar, 50));

cmd.Parameters.Add(new SqlParameter("@pvchCustId", SqlDbType.Int));

cmd.Parameters.Add(new SqlParameter("@pvchCustName", SqlDbType.VarChar, 100));

cmd.Parameters.Add(new SqlParameter("@pvchustaddress1", SqlDbType.VarChar, 100));

cmd.Parameters.Add(new SqlParameter("@pvchustaddress2", SqlDbType.VarChar, 100));

cmd.Parameters.Add(new SqlParameter("@pvchCustPhone", SqlDbType.VarChar, 100));

cmd.Parameters.Add(new SqlParameter("@pvchCustEmail", SqlDbType.VarChar, 100));

cmd.Parameters.Add(new SqlParameter("@pvchCreatedBy", SqlDbType.VarChar, 100));

cmd.Parameters.Add("@pIntErrDescOut", SqlDbType.Int).Direction = ParameterDirection.Output;

cmd.Parameters["@pvchAction"].Value = "update";

cmd.Parameters["@pvchCustId"].Value = Convert.ToInt32(Custid.Text.ToString());

cmd.Parameters["@pvchCustName"].Value = Name.Text.Trim();

cmd.Parameters["@pvchustaddress1"].Value = Address1.Text.Trim();

cmd.Parameters["@pvchustaddress2"].Value = Address2.Text.Trim();

cmd.Parameters["@pvchCustPhone"].Value = Phone.Text.Trim();

cmd.Parameters["@pvchCustEmail"].Value = Email.Text.Trim();

cmd.Parameters["@pvchCreatedBy"].Value = "Admin";

cmd.ExecuteNonQuery();

int retVal = (int)cmd.Parameters["@pIntErrDescOut"].Value;

}

}

GridViewSample.EditIndex = -1;

LoadData();

lblMessage.Text = "Record updated successfully!";

}
Reply With Quote
  #4 (permalink)  
Old June 16th, 2017, 12:18 PM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2017
Location: lahore
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default thanks

Thank you izofile sir
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Update/delete using gridview dhall ASP.NET 4 General Discussion 0 March 23rd, 2016 03:44 PM
data gridview update, delete and insert to multi database khoonng BOOK: Beginning ASP.NET 4 : in C# and VB 1 December 13th, 2013 03:17 AM
Insert, update, delete in gridview-!!! URGENT !!! dagad ASP.NET 2.0 Basics 0 September 27th, 2006 06:24 AM



All times are GMT -4. The time now is 04:46 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.