แก้ไข

แชร์ผ่าน


DataRow.IsNull Method

Definition

Gets a value that indicates whether the specified column contains a null value.

Overloads

IsNull(DataColumn)

Gets a value that indicates whether the specified DataColumn contains a null value.

IsNull(Int32)

Gets a value that indicates whether the column at the specified index contains a null value.

IsNull(String)

Gets a value that indicates whether the named column contains a null value.

IsNull(DataColumn, DataRowVersion)

Gets a value that indicates whether the specified DataColumn and DataRowVersion contains a null value.

IsNull(DataColumn)

Source:
DataRow.cs
Source:
DataRow.cs
Source:
DataRow.cs

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

Returns

true if the column contains a null value; otherwise, false.

Exceptions

column is null.

The row does not belong to the table.

Examples

The following example prints each column of each row in each table of a DataSet. 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

Applies to

IsNull(Int32)

Source:
DataRow.cs
Source:
DataRow.cs
Source:
DataRow.cs

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

true if the column contains a null value; otherwise, false.

Exceptions

No column corresponds to the index specified by columnIndex.

The row does not belong to the table.

Examples

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

Applies to

IsNull(String)

Source:
DataRow.cs
Source:
DataRow.cs
Source:
DataRow.cs

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

true if the column contains a null value; otherwise, false.

Exceptions

The column specified by columnName cannot be found.

columnName is null.

The row does not belong to the table.

Examples

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

Applies to

IsNull(DataColumn, DataRowVersion)

Source:
DataRow.cs
Source:
DataRow.cs
Source:
DataRow.cs

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

version
DataRowVersion

One of the DataRowVersion values that specifies the row version. Possible values are Default, Original, Current, and Proposed.

Returns

true if the column contains a null value; otherwise, false.

Exceptions

column is null.

The row does not belong to the table.

The row does not have the requested version.

Applies to