2017-01-20 1 views
0

그의 코드에 catch(Exception) 조항이있는 this guy을 돕고 싶었습니다. 나쁜 습관. 특정 예외를 잡아야합니다. 좋아, 그래서 뭐야?DataSet.Fill을 사용하여 오류를 처리하는 방법은 무엇입니까?

그가 유일한 호출 방법 인 OdbcAdapter.Fill(DataSet)에 대한 설명서를 참조하고 가능한 모든 예외를 나열하는 입력/출력 목록을 찾았습니다. 나열된 없음 어떤 것을 던지나요?

그렇다면 Fill은 예외를 throw하지 않는다는 것을 알았습니다. 예외를 throw하고 대신 events을 발생시킵니다.

그러나 그 때 나는 this를 발견했다.

this.

OdbcDataAdapter.Fill(DataSet) 예외가 발생하는지 여부 예외는 무엇입니까? 그것은 사건을 일으키는가 아닌가?

답변

0

그게 도움이 될 수도 있습니다.

다음 코드 예제에서는 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

관련 문제