Click to See Complete Forum and Search --> : Record not updated


devpro
June 26th, 2001, 03:57 PM
I have the following code in the Update event of a Grid:

protected void MyGrid_Update(object sender, DataGridCommandEventArgs e)
{
string updateCmd = "UPDATE TestTable SET City = @City WHERE ID = @ID";
ADOConnection myConn = new ADOConnection(ConnString);
myConn.Open();

ADOCommand myCmd = new ADOCommand(updateCmd, myConn);
// create the params
myCmd.Parameters.Add(new ADOParameter("@ID", ADODBType.Integer, 4));
myCmd.Parameters["@ID"].Value =
(int)MyGrid.DataKeys[(int)e.Item.ItemIndex];
myCmd.Parameters.Add(new ADOParameter("@City", ADODBType.VarChar, 50));
myCmd.Parameters["@City"].Value =
((TextBox)e.Item.FindControl("City")).Text;

// execute
myCmd.ExecuteNonQuery();
myConn.Close();

//rebind
MyGrid.EditItemIndex = -1;
BindGrid();
}

when the code is executed, the values are corretly extracted from the
textbox and the DataKeys prop, but the record is not updated. Can you say
why??

- devpro