下面的taskvision中代码
移植到vS2008,按下面方法给dbEx.Row赋值后,dbEx.Row的hasErrors属性变成false了。是什么原因啊?
try
{
daTasks.Update(dsTasks, "Tasks");
break;
}
catch (DBConcurrencyException dbEx)
{
// we're here because either the row was changed by someone else
// or deleted by the dba, let's try get the updated row
DataSet ds = new DataSet();
SqlCommand cmd = new SqlCommand("GetOneTask", sqlConn);
cmd.CommandType = CommandType.StoredProcedure;
// get the updated row
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.SelectCommand.Parameters.Add("@TaskID", dbEx.Row["TaskID"]);
da.Fill(ds);
// if the row still exists
if (ds.Tables[0].Rows.Count > 0)
{
DataRow proposedRow = dbEx.Row.Table.NewRow();
DataRow databaseRow = ds.Tables[0].Rows[0];
// copy the attempted changes
proposedRow.ItemArray = dbEx.Row.ItemArray;
// set the row with what's in the database and then re-apply
// the proposed changes.
dbEx.Row.Table.Columns["TaskID"].ReadOnly = false;
dbEx.Row.ItemArray = databaseRow.ItemArray;//只要给dbEx.Row赋值,dbEx.Row.HasErrors就会变成false,重新设置dbEx.Row.RowError不为空也没用
dbEx.Row.AcceptChanges();
dbEx.Row.ItemArray = proposedRow.ItemArray;
dbEx.Row.Table.Columns["TaskID"].ReadOnly = true;
// note: because this row triggers an ADO.NET exception,
// the row was tagged with a rowerror property which we'll leave for the client app
return dsTasks;
}
dbEx.Row.ItemArray = databaseRow.ItemArray;//databaseRow.ItemArray它应该是空吧?