UpdateCommand Error - Object not set to an instance of an object.

UpdateCommand Error - Object not set to an instance of an object.

Post by Michael Hetric » Thu, 29 May 2003 09:06:19



I'm receiving an error noted below in the UpdateCommand Event.  I was
working from the "Using a DataGrid Web Control to Read and Write Data
Walkthrough" in the VS Help and the Products table of the Northwind DB.

Can someone tell me what I'm doing wrong?  Thanks.

Michael Hetrick
private void DataGrid1_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)

{
string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
string productName = ((TextBox)e.Item.Cells[2].Controls[0]).Text;

//Returns the value of the ProductID and updated ProductName from the
textbox.
Response.Write(key + " " + productName);

dsProducts.ProductsRow r;
r = dsProducts1.Products.FindByProductID(int.Parse(key));

// --> get error - Object reference not set to an instance of an object.
r.ProductName = productName;

sqlDataAdapter1.Update(dsProducts1);
DataGrid1.EditItemIndex = -1;
BindGrid();

Quote:}