DataRow.SetColumnError 方法

定義

設定資料行的錯誤描述。

多載

SetColumnError(DataColumn, String)

對指定為 DataColumn 的資料行設定錯誤描述。

SetColumnError(Int32, String)

設定索引指定的資料行的錯誤描述。

SetColumnError(String, String)

設定名稱指定的資料行的錯誤描述。

SetColumnError(DataColumn, String)

來源:
DataRow.cs
來源:
DataRow.cs
來源:
DataRow.cs

對指定為 DataColumn 的資料行設定錯誤描述。

public:
 void SetColumnError(System::Data::DataColumn ^ column, System::String ^ error);
public void SetColumnError (System.Data.DataColumn column, string? error);
public void SetColumnError (System.Data.DataColumn column, string error);
member this.SetColumnError : System.Data.DataColumn * string -> unit
Public Sub SetColumnError (column As DataColumn, error As String)

參數

column
DataColumn

要為其設定錯誤描述的 DataColumn

error
String

錯誤描述。

範例

下列範例會設定指定 DataRow之的錯誤描述。

private void SetColError(DataRow row, int columnIndex)
{
    string errorString = "Replace this text.";

    // Set the error for the specified column of the row.
    row.SetColumnError(columnIndex, errorString);
}

private void PrintColError(DataRow row, int columnIndex)
{
    // Print the error of a specified column.
    Console.WriteLine(row.GetColumnError(columnIndex));
}
Private Sub SetColError(ByVal row As DataRow, _
    byVal columnIndex As Integer)
    Dim errorString As String = "Replace this text."

    ' Set the error for the specified column of the row.
    row.SetColumnError(columnIndex, errorString)
End Sub
 
Private Sub PrintColError( _
    ByVal row As DataRow, byVal columnIndex As Integer)

    ' Print the error of a specified column.
    Console.WriteLine(row.GetColumnError(columnIndex))
End Sub

備註

若要檢查錯誤描述,請使用 GetColumnError 方法。

若要判斷資料行集合是否有任何錯誤,請使用 HasErrors 屬性。 因此,您可以使用 GetColumnsInError 方法來擷取所有發生錯誤的數據行。

如果 null 或空字串是以 error 參數的形式傳入,則 DataRow 的行為就如同未設定任何錯誤,而且 HasErrors 屬性會傳回 false。

若要在整列上設定自定義錯誤描述,請使用 RowError 屬性。

若要判斷數據行集合是否有任何錯誤,請使用 HasErrors 方法。

若要清除資料行集合的所有錯誤,請使用 ClearErrors 方法。

另請參閱

適用於

SetColumnError(Int32, String)

來源:
DataRow.cs
來源:
DataRow.cs
來源:
DataRow.cs

設定索引指定的資料行的錯誤描述。

public:
 void SetColumnError(int columnIndex, System::String ^ error);
public void SetColumnError (int columnIndex, string? error);
public void SetColumnError (int columnIndex, string error);
member this.SetColumnError : int * string -> unit
Public Sub SetColumnError (columnIndex As Integer, error As String)

參數

columnIndex
Int32

資料行的以零起始的索引。

error
String

錯誤描述。

例外狀況

columnIndex 引數超出範圍

範例

下列範例會設定指定 DataRow之的錯誤描述。

private void SetColError(DataRow row, int columnIndex)
{
    string errorString = "Replace this text.";

    // Set the error for the specified column of the row.
    row.SetColumnError(columnIndex, errorString);
}

private void PrintColError(DataRow row, int columnIndex)
{
    // Print the error of a specified column.
    Console.WriteLine(row.GetColumnError(columnIndex));
}
Private Sub SetColError(ByVal row As DataRow, _
    byVal columnIndex As Integer)
    Dim errorString As String = "Replace this text."

    ' Set the error for the specified column of the row.
    row.SetColumnError(columnIndex, errorString)
End Sub
 
Private Sub PrintColError( _
    ByVal row As DataRow, byVal columnIndex As Integer)

    ' Print the error of a specified column.
    Console.WriteLine(row.GetColumnError(columnIndex))
End Sub

備註

方法可用來在指定的數據行上設定自定義錯誤描述。 您可以使用 ErrorProvider 控制項來顯示錯誤的文字。

若要檢查錯誤描述,請使用 GetColumnError 方法。

若要判斷資料行集合是否有任何錯誤,請使用 HasErrors 屬性。 因此,您可以使用 GetColumnsInError 方法來擷取所有發生錯誤的數據行。

如果 null 或空字串是以 error 參數的形式傳入,則 DataRow 的行為就如同未設定任何錯誤,而且 HasErrors 屬性會傳回 false。

若要在整列上設定自定義錯誤描述,請使用 RowError 屬性。

若要清除資料行集合的所有錯誤,請使用 ClearErrors 方法。

若要設定套用至整列的錯誤文字,請設定 RowError 屬性。

另請參閱

適用於

SetColumnError(String, String)

來源:
DataRow.cs
來源:
DataRow.cs
來源:
DataRow.cs

設定名稱指定的資料行的錯誤描述。

public:
 void SetColumnError(System::String ^ columnName, System::String ^ error);
public void SetColumnError (string columnName, string? error);
public void SetColumnError (string columnName, string error);
member this.SetColumnError : string * string -> unit
Public Sub SetColumnError (columnName As String, error As String)

參數

columnName
String

資料行名稱。

error
String

錯誤描述。

範例

下列範例會設定指定 DataRow之的錯誤描述。

private void SetColError(DataRow row, int columnIndex)
{
    string errorString = "Replace this text.";

    // Set the error for the specified column of the row.
    row.SetColumnError(columnIndex, errorString);
}

private void PrintColError(DataRow row, int columnIndex)
{
    // Print the error of a specified column.
    Console.WriteLine(row.GetColumnError(columnIndex));
}
Private Sub SetColError(ByVal row As DataRow, _
    byVal columnIndex As Integer)
    Dim errorString As String = "Replace this text."

    ' Set the error for the specified column of the row.
    row.SetColumnError(columnIndex, errorString)
End Sub
 
Private Sub PrintColError( _
    ByVal row As DataRow, byVal columnIndex As Integer)

    ' Print the error of a specified column.
    Console.WriteLine(row.GetColumnError(columnIndex))
End Sub

備註

數據行的名稱是使用 ColumnName 類別的 DataColumn 屬性來設定。

若要檢查錯誤描述,請使用 GetColumnError 方法。

若要判斷資料行集合是否有任何錯誤,請使用 HasErrors 屬性。 因此,您可以使用 GetColumnsInError 方法來擷取所有發生錯誤的數據行。

如果 null 或空字串是以 error 參數的形式傳入,則 DataRow 的行為就如同未設定任何錯誤,而且 HasErrors 屬性會傳回 false。

若要在整列上設定自定義錯誤描述,請使用 RowError 屬性。

若要判斷數據行集合是否有任何錯誤,請使用 HasErrors 方法。

若要清除資料行集合的所有錯誤,請使用 ClearErrors 方法。

另請參閱

適用於