ADO.NET对象的构造(5)_DataRow(续)

王朝c#·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

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)

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航