mercoledì 17 giugno 2009

Dataset find and edit a row

First of all to use the dataset/datatable find method we have to define a column key:

datatable1.PrimaryKey = New DataColumn() {datatable1.Columns(0)}

second step, we do a find over the key column :

Dim dr as DataRow
dr = datatable1.rows.find('value to find')
If dr IsNot Nothing Then
...your code
End If

if we want update the row that we found in the original datatable we have to add this code:

Dim dr as DataRow
dr = datatable1.rows.find('value to find')
If dr IsNot Nothing Then
dr.BeginEdit()
dr.Item("PhoneNumber") = "04-5492302"
datatable1.AcceptChanges()
dr.EndEdit()
End If

in this way we have made a change in the original datatable

0 commenti:

Posta un commento