Click here to Skip to main content
15,917,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

update gridview row records in

below code press "add" button in gridview update first row

here below code working update all records data i want only update first row

protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
        SqlConnection a = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        string cartCmd = "update tbldata set status='Y' where status='N'";
        SqlCommand cmd = new SqlCommand(cartCmd, a);
        SqlDataAdapter sda = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        GridView2.DataSource = ds;

please reply me here what modification
Updated 11-Nov-14 18:19pm
Mitesh Prajapati14 12-Nov-14 1:02am    
As per your code you need to pass record primary key in where condition. so it will not update all the record in db.

Current query will update all status where status='N'

your new query should be like this :
"update tbldata set status='Y' where status='N' and id=@id"

1 solution

Share this answer

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