Let's say you invoke the update method of the SQlDataAdapter:
MyDataSet.Tables[0].DefaultView.RowStateFilter = DataViewRowState.ModifiedCurrent;
if (MyDataSet.Tables[0].DefaultView.Count > 0)
{
MySqlAdapter.Update(DS.Tables[0].DefaultView.Table);
}
and your user happens to have left a required column NULL, so the back-end complains about it, and your catch block traps the "cannot be null" sql exception. How do you clear the error state so that ADO.NET doesn't keep raising the same error again and again, even when the user supplies the required value? What object's method should be invoked, or what property should be changed, to put the adapter back into a state wher开发者_如何学JAVAe the update can occur, as long as the missing value is supplied?
This doesn't seem to be enough:
internal void OnRowUpdating(object sender, System.Data.SqlClient.SqlRowUpdatingEventArgs e)
{
if (e.Status == UpdateStatus.ErrorsOccurred)
{
e.Row.RowError = e.Errors.Message;
e.Status = UpdateStatus.SkipCurrentRow;
}
}
When the user fills in the required value the "cannot be null" exception will go away. It's that easy, but then again I do the saving this way:
DataTable changes=MyDataSet.Tables[0].GetChanges();
if (changes!=null)
{
MySqlAdapter.Update(changes);
MyDataSet.Tables[0].AcceptChanges();
}
精彩评论