n IsNull 方法
n Overloads Public Function IsNull(ByVal column As DataColumn ) As Boolean
n Overloads Public Function IsNull(ByVal columnIndex As Integer ) As Boolean
n Overloads Public Function IsNull(ByVal columnName As String ) As Boolean
n Overloads Public Function IsNull(ByVal column As DataColumn , ByVal version As DataRowVersion ) As Boolean
参数
1. column DataColumn 。
2. columnIndex 列的从零开始的索引。
3. columnName 列的名称。
4. version DataRowVersion 值之一,它指定行版本。可能值为 Default 、 Original 、 Current 和 Proposed 。
示例 1
以下示例将列的值更改为空值,然后使用 IsNull 方法来确定该值是否为空。
Private Sub IsValNull()
Dim t As DataTable
Dim r As DataRow
' Assuming the DataGrid is bound to a DataTable.
t = CType(DataGrid1.DataSource, DataTable)
r = t.Rows(datagrid1.CurrentCell.RowNumber)
r.BeginEdit
r("FirstName") = System.DBNull.Value’ r(1) = System.DBNull.Value
r.EndEdit
r.AcceptChanges
Console.WriteLine(r.IsNull("FirstName"))’ Console.WriteLine(r.IsNull(1))
End Sub
示例 2
Private Sub PrintRows(ds As DataSet)
Dim t As DataTable
Dim c As DataColumn
Dim r As DataRow
For Each t In ds.Tables
For Each r In t.Rows
For Each c In t.Columns
If Not r.IsNull(c) Then Console.WriteLine(r(c).ToString())
Next c
Next r
Next t
End Sub
n Overloads Public Overridable Function Add(ByVal values () As Object ) As DataRow ’ 如果在 ColumnChanging 或 RowChanging 事件过程中生成异常,则也可发生异常。如果发生异常,则不向表中添加行。
n Overloads Public Sub Add(ByVal row As DataRow )’ 如果用户在 RowChanging 事件中生成异常,则生成异常。如果发生异常,则不向表中添加行。
示例
Private Sub AddRow(ByVal myTable As DataTable)
Dim rc As DataRowCollection= myTable.Rows
Dim myNewRow As DataRow
Dim rowVals(1) As Object
rowVals(0) = "hello"
rowVals(1) = "world"
myNewRow = rc.Add(rowVals)
newRow = myTable. NewRow ()
newRow(0) = "hello"
newRow(1) = "world"
rc.Add(newRow)
End Sub
( 信息整理来自 MSDN)