我用DataRow dr = this.dsCategories1.Categories.NewRow();增加了一行,具体如下:
DataRow dr = this.dsCategories1.Categories.NewRow();
dr["CategoryID"]=10;
dr["CategoryName"]="test";
//dr["Description"]="test";
this.dsCategories1.Categories.Rows.InsertAt(dr,0);
DataGrid1.EditItemIndex = 0;
DataGrid1.DataBind();然后在页面输入数据后点更新,结果老是说“未将对象引用设置到对象的实例。”
dsCategories.CategoriesRow r; 

r = dsCategories1.Categories.FindByCategoryID(int.Parse(key)); 
// Updates the dataset table. 
r.CategoryName = categoryName; 
r.Description = categoryDescription; 
// Calls a SQL statement to update the database from the dataset 
sqlDataAdapter1.Update(dsCategories1); 
// Takes the DataGrid row out of editing mode 
DataGrid1.EditItemIndex = -1; 
// Refreshes the grid 
DataGrid1.DataBind(); 
单步跟踪后发现是r = dsCategories1.Categories.FindByCategoryID(int.Parse(key)); 
导致的错误,但是我在增加新行的时候已经赋值了呀dr["CategoryID"]=10;