它可能會幫助你。
以下代碼示例爲DataAdapter的FillError事件添加事件處理程序。在FillError事件代碼中,該示例確定是否存在精度損失的可能性,從而提供對異常做出響應的機會。
adapter.FillError += new FillErrorEventHandler(FillError);
DataSet dataSet = new DataSet();
adapter.Fill(dataSet, "ThisTable");
protected static void FillError(object sender, FillErrorEventArgs args)
{
if (args.Errors.GetType() == typeof(System.OverflowException))
{
// Code to handle precision loss.
//Add a row to table using the values from the first two
columns.
DataRow myRow = args.DataTable.Rows.Add(new object[]
{args.Values[0], args.Values[1], DBNull.Value});
//Set the RowError containing the value for the third column.
args.RowError =
"OverflowException Encountered. Value from data source: " +
args.Values[2];
args.Continue = true;
}
}
參考:https://msdn.microsoft.com/en-us/library/6d1wk41s(v=vs.110).aspx