thanQ very much for the reply
Sorry,this time I got another exception
actually I want update one row in the database and not total fields some of the fields I want to update
In mygirdview I have the information like this
empId userName empName gender address pwd loginstatus edit 1 geeta geeta f hjghg ghh 0
so here I want to change the userName with kavita
after clicking the edit button it will come like this
empId userName empName gender address pwd loginstatus update cancel 1 kavita geeta f hjghg ghh 0
after that I clicked on the update link
but now I got another exception
I wrote the code lke following
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindData();
}
}
public void BindData()
{
conn.Open();
SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROM EmployeeTable", conn);
DataSet ds = new DataSet();
ad.Fill(ds, "EmployeeTable");
conn.Close();
myGridView.DataSource = ds;
myGridView.DataBind();
}
protected void myGridView_RowCancelingEdit(object sender,GridViewCancelEditEventArgs e)
{
myGridView.EditIndex = -1;
BindData();
}
protected void updateRow(object sender, GridViewUpdateEventArgs e)
{
string id = myGridView.DataKeys[e.RowIndex].Value.ToString();
TextBox txtName = (TextBox)myGridView.Rows[e.RowIndex].FindControl("txtName");
conn.Open();
SqlCommand UpdateCmd = new SqlCommand("update EmployeeTable set text='" + txtName + "' where empId=" + id,conn);
UpdateCmd.ExecuteNonQuery();
conn.Close();
myGridView.EditIndex = -1; //After updating, please set EditIndex and re-bind the GridView.
BindData();
}
string id = myGridView.DataKeys[e.RowIndex].Value.ToString();here I am getting the exception i.e Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
So where to change the code
please help me in this.....................