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

update gridview row records in asp.net

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

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

C#
protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        SqlConnection a = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        a.Open();
        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();
        sda.Fill(ds);
        GridView2.DataSource = ds;
        GridView2.DataBind();
        a.Close();
    }



please reply me here what modification
Posted
Updated 11-Nov-14 18:19pm
v2
Comments
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