DataRow.IsNull Method

Definition

获取一个值,该值指示指定的列是否包含 null 值。Gets a value that indicates whether the specified column contains a null value.

Overloads

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

Parameters

column
DataColumn

一个 DataColumnA DataColumn.

Returns

Boolean

如果该列包含 null 值,则为 true;否则为 falsetrue if the column contains a null value; otherwise, false.

Exceptions

columnnullcolumn is null.

此行不属于该表。The row does not belong to the table.

Examples

下面的示例将打印 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

Parameters

columnIndex
Int32

列的从零开始的索引。The zero-based index of the column.

Returns

Boolean

如果该列包含 null 值,则为 true;否则为 falsetrue if the column contains a null value; otherwise, false.

Exceptions

没有列对应于 columnIndex 指定的索引。No column corresponds to the index specified by columnIndex.

此行不属于该表。The row does not belong to the table.

Examples

下面的示例将列的值更改为 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

Parameters

columnName
String

列的名称。The name of the column.

Returns

Boolean

如果该列包含 null 值,则为 true;否则为 falsetrue if the column contains a null value; otherwise, false.

Exceptions

找不到由 columnName 指定的列。The column specified by columnName cannot be found.

columnNamenullcolumnName is null.

此行不属于该表。The row does not belong to the table.

Examples

下面的示例将列的值更改为 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

Parameters

column
DataColumn

一个 DataColumnA DataColumn.

version
DataRowVersion

DataRowVersion 值之一,用于指定行版本。One of the DataRowVersion values that specifies the row version. 可能值为 DefaultOriginalCurrentProposedPossible values are Default, Original, Current, and Proposed.

Returns

Boolean

如果该列包含 null 值,则为 true;否则为 falsetrue if the column contains a null value; otherwise, false.

Exceptions

columnnullcolumn is null.

此行不属于该表。The row does not belong to the table.

该行没有请求的 versionThe row does not have the requested version.

Applies to