Click here to Skip to main content
16,016,527 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi To All.
This is My Code To Update My GridView But Cannot Update the Record
C#
protected void GrdViewCont_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            Label Lblid = (Label)GrdViewCont.Rows[e.RowIndex].FindControl("LblNo");
            TextBox txtNam = (TextBox)GrdViewCont.Rows[e.RowIndex].FindControl("txtName");
            Label Lbltp = (Label)GrdViewCont.Rows[e.RowIndex].FindControl("LblType");

            SqlCommand cmd = new SqlCommand("update ContarctorDefTable set Contractor_Name = '" + txtNam.Text + "'" +
                            ",Contractor_Type='" + LblType.Text + "' where ID = '" + Lblid.Text + "'", conn);
            conn.Open();
            SqlDataReader reader;
            reader = cmd.ExecuteReader();
            conn.Close();
        
            GrdViewCont.EditIndex = -1;
            BindGrdViewCont();
        }

Please Help To Me.
Posted
Updated 11-Sep-13 0:58am
v2

Replace cmd.ExecuteReader() with cmd.ExecuteNonQuery()
Go through this link
http://www.aspdotnet-suresh.com/2011/02/how-to-inserteditupdate-and-delete-data.html[^]
 
Share this answer
 
v2
Why you people rely solely on others. Google has atleast 1230000 results for this. Should we assume that none of them works for you?

https://www.google.co.in/search?q=gridview+update+asp.net&oq=gridview+update+asp.net&aqs=chrome..69i57j69i65l3j0l2.7091j0&sourceid=chrome&ie=UTF-8[^]
 
Share this answer
 
what is the error u getting?

so tht i can chk here
 
Share this answer
 
Comments
Assaad_AW 11-Sep-13 23:31pm    
HiNo Error But Record not update

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