DataRow.GetColumnsInError 方法
本文內容
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得具有錯誤的資料行陣列。
public:
cli::array <System::Data::DataColumn ^> ^ GetColumnsInError();
public System.Data.DataColumn[] GetColumnsInError ();
member this.GetColumnsInError : unit -> System.Data.DataColumn[]
Public Function GetColumnsInError () As DataColumn()
包含錯誤的 DataColumn 物件陣列。
下列範例會使用 HasErrors 來尋找錯誤。 如果數據列有錯誤,此方法會 GetColumnsInError 傳回數據行陣列,並接著可以解決這些錯誤。 接著會 ClearErrors 呼叫 方法,以清除所有錯誤。
private void GetAllErrs(DataRow row)
{
// Declare an array variable for DataColumn objects.
DataColumn[] colArr;
// If the Row has errors, check use GetColumnsInError.
if(row.HasErrors)
{
// Get the array of columns in error.
colArr = row.GetColumnsInError();
for(int i = 0; i < colArr.Length; i++)
{
// Insert code to fix errors on each column.
Console.WriteLine(colArr[i].ColumnName);
}
// Clear errors after reconciling.
row.ClearErrors();
}
}
Private Sub GetAllErrs(ByVal row As DataRow)
' Declare an array variable for DataColumn objects.
Dim colArr() As DataColumn
' If the Row has errors, check use GetColumnsInError.
Dim i As Integer
If row.HasErrors Then
' Get the array of columns in error.
colArr = row.GetColumnsInError()
For i = 0 to colArr.GetUpperBound(0)
' Insert code to fix errors on each column.
Console.WriteLine(colArr(i).ColumnName)
Next i
' Clear errors after reconciling.
row.ClearErrors()
End If
End Sub
GetColumnsInError可讓您只傳回有錯誤的數據行,以減少必須針對錯誤處理的物件數目DataColumn。 您可以使用 方法,將錯誤設定為個別數據行 SetColumnError 。 若要進一步減少處理次數,請檢查 HasErrors 類別的 DataRow 屬性,以判斷 是否 DataRow 在叫用 GetColumnsInError之前發生錯誤。
ClearErrors使用方法來清除資料列上的所有錯誤。 這包括 RowError。
| 產品 | 版本 |
|---|---|
| .NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
| .NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
| .NET Standard | 2.0, 2.1 |