Click here to Skip to main content
15,886,661 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C#
protected void griddelete_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            using (SqlConnection con = new SqlConnection(cs))
            {
                GridViewRow updaterow = (GridViewRow)griddelete.Rows[e.RowIndex];
                TextBox updatel1 = (TextBox)updaterow.FindControl("txtempidrow");
                TextBox updatel2 = (TextBox)updaterow.FindControl("txtnamerow");
                TextBox updatel3 = (TextBox)updaterow.FindControl("txtjobrow");
                string update = "update emp set job=@job,ename=@ename where empno=@empno";
                con.Open();
                SqlCommand cmd = new SqlCommand(update,con);

                cmd.Parameters.AddWithValue("@empno", updatel1.Text);
                cmd.Parameters.AddWithValue("@ename", updatel2.Text);
                cmd.Parameters.AddWithValue("@job", updatel3.Text);
                cmd.ExecuteNonQuery();
                griddelete.EditIndex = -1;
               
                lblmsg.Text = "Data Updated successfully";
                bind();
                
            }

        }


//
(when i am trying this it works correctly and printing message but data not updating)
Posted
Updated 18-Feb-15 6:18am
v3
Comments
King Fisher 18-Feb-15 7:23am    
Any error?check updatel1 ,updatel2 and updatel3 have values? and your are trying to update so does your table have corresponding values of updatel3 ?
better use try catch block to catch Error .
Member 10458660 18-Feb-15 7:29am    
Yes It contains values but when i update the data it will not updating it will show same data.. can you write the code for me
King Fisher 18-Feb-15 7:37am    
Did you check whether your Updatel1 value is matched with table values?
Member 10458660 18-Feb-15 12:12pm    
yes,it was matched...
Richard Deeming 18-Feb-15 12:56pm    
What does the bind() method look like?

(Use the "Improve question" link to add the code to your question. Code posted in the comments isn't very readable.)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900