Hi Friend,
I am trying to update the gridview.I wrote the code also, the problem is when i update a single row its update all the data in database.
Here is my code for your reference.
protected void addpro_Grid2_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string pid = ((TextBox)addpro_Grid2.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
string pname = ((TextBox)addpro_Grid2.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
addpro_Grid_Update(pid, pname);
addpro_Grid2.EditIndex = -1;
fill();
}
protected void fill()
{
cmd = new SqlCommand("select * from masters_addproduct", con);
da = new SqlDataAdapter(cmd);
dt = new DataTable();
da.Fill(dt);
addpro_Grid2.DataSource = dt;
addpro_Grid2.DataBind();
}
public void addpro_Grid_Update(string pid, string pname)
{
cmd = new SqlCommand("update masters_addproduct set pid='" + pid + "',p_name='" + pname + "'", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
How can i update the gridview data using identity column in db.
update masters_addproduct set p_name='"+pname+"' where pid=@pid"
If i execute this code it shows error.
Must declare scalar variable pid..
How to overcome this problem.
Thanks in Advance.