DataRow.IsNull 方法

定義

取得值,指出指定的資料行是否包含 Null 值。Gets a value that indicates whether the specified column contains a null value.

多載

IsNull(DataColumn)

取得值,指出指定的 DataColumn 是否含有 Null 值。Gets a value that indicates whether the specified DataColumn contains a null value.

IsNull(Int32)

取得值,指出指定之索引處的資料行是否包含 Null 值。Gets a value that indicates whether the column at the specified index contains a null value.

IsNull(String)

取得值,指出具名資料行是否包含 Null 值。Gets a value that indicates whether the named column contains a null value.

IsNull(DataColumn, DataRowVersion)

取得值,指出指定的 DataColumnDataRowVersion 是否包含 Null 值。Gets a value that indicates whether the specified DataColumn and DataRowVersion contains a null value.

IsNull(DataColumn)

取得值,指出指定的 DataColumn 是否含有 Null 值。Gets a value that indicates whether the specified DataColumn contains a null value.

public:
 bool IsNull(System::Data::DataColumn ^ column);
public bool IsNull (System.Data.DataColumn column);
member this.IsNull : System.Data.DataColumn -> bool
Public Function IsNull (column As DataColumn) As Boolean

參數

傳回

如果資料行包含 Null 值,則為 true,否則為 falsetrue if the column contains a null value; otherwise, false.

例外狀況

columnnullcolumn is null.

資料列不屬於資料表。The row does not belong to the table.

範例

下列範例會列印 DataSet之每個資料表中每個資料列的每個資料行。The following example prints each column of each row in each table of a DataSet. 如果資料列設定為 null 值,則不會列印值。If the row is set to a null value, the value is not printed.

Private Sub PrintRows(dataSet As DataSet)
    Dim table As DataTable
    Dim column As DataColumn
    Dim row As DataRow
    For Each table In dataSet.Tables
       For Each row In table.Rows
          For Each column In table.Columns
             If Not row.IsNull(column) Then 
                Console.WriteLine(row(column).ToString())
             End If
          Next column
       Next row
     Next table
End Sub

IsNull(Int32)

取得值,指出指定之索引處的資料行是否包含 Null 值。Gets a value that indicates whether the column at the specified index contains a null value.

public:
 bool IsNull(int columnIndex);
public bool IsNull (int columnIndex);
member this.IsNull : int -> bool
Public Function IsNull (columnIndex As Integer) As Boolean

參數

columnIndex
Int32

資料行的以零起始的索引。The zero-based index of the column.

傳回

如果資料行包含 Null 值,則為 true,否則為 falsetrue if the column contains a null value; otherwise, false.

例外狀況

無資料行對應至 columnIndex 指定的索引。No column corresponds to the index specified by columnIndex.

資料列不屬於資料表。The row does not belong to the table.

範例

下列範例會將資料行的值變更為 null 值,然後使用 IsNull 方法來判斷值是否為 null。The following example changes the value of a column to a null value, and then uses the IsNull method to determine whether the value is null.

Private Sub IsValNull()
    ' Assuming the DataGrid is bound to a DataTable.
    Dim table As DataTable = CType(DataGrid1.DataSource, DataTable)
    Dim row As DataRow = table.Rows(datagrid1.CurrentCell.RowNumber)
    row.BeginEdit
    row(1) = System.DBNull.Value
    row.EndEdit
    row.AcceptChanges
    Console.WriteLine(row.IsNull(1))
End Sub

IsNull(String)

取得值,指出具名資料行是否包含 Null 值。Gets a value that indicates whether the named column contains a null value.

public:
 bool IsNull(System::String ^ columnName);
public bool IsNull (string columnName);
member this.IsNull : string -> bool
Public Function IsNull (columnName As String) As Boolean

參數

columnName
String

資料行名稱。The name of the column.

傳回

如果資料行包含 Null 值,則為 true,否則為 falsetrue if the column contains a null value; otherwise, false.

例外狀況

找不到 columnName 指定的資料行。The column specified by columnName cannot be found.

columnNamenullcolumnName is null.

資料列不屬於資料表。The row does not belong to the table.

範例

下列範例會將資料行的值變更為 null 值,然後使用 IsNull 方法來判斷值是否為 null。The following example changes the value of a column to a null value, and then uses the IsNull method to determine whether the value is null.

 Private Sub IsValNull()
    ' Assuming the DataGrid is bound to a DataTable.
    Dim table As DataTable = CType(DataGrid1.DataSource, DataTable)
    Dim row As DataRow = table.Rows(datagrid1.CurrentCell.RowNumber)
    row.BeginEdit
    row("FirstName") = System.DBNull.Value
    row.EndEdit
    row.AcceptChanges
    Console.WriteLine(row.IsNull("FirstName"))
End Sub

IsNull(DataColumn, DataRowVersion)

取得值,指出指定的 DataColumnDataRowVersion 是否包含 Null 值。Gets a value that indicates whether the specified DataColumn and DataRowVersion contains a null value.

public:
 bool IsNull(System::Data::DataColumn ^ column, System::Data::DataRowVersion version);
public bool IsNull (System.Data.DataColumn column, System.Data.DataRowVersion version);
member this.IsNull : System.Data.DataColumn * System.Data.DataRowVersion -> bool
Public Function IsNull (column As DataColumn, version As DataRowVersion) As Boolean

參數

version
DataRowVersion

其中一個 DataRowVersion 值,指定資料列的版本。One of the DataRowVersion values that specifies the row version. 可能的值為 DefaultOriginalCurrentProposedPossible values are Default, Original, Current, and Proposed.

傳回

如果資料行包含 Null 值,則為 true,否則為 falsetrue if the column contains a null value; otherwise, false.

例外狀況

columnnullcolumn is null.

資料列不屬於資料表。The row does not belong to the table.

資料列沒有要求的 versionThe row does not have the requested version.

適用於