Q: Updating a single row

  • Thread starter Thread starter Geoff Jones
  • Start date Start date
G

Geoff Jones

Hi

Using code like:

dataAdaptor1.Update(dataSet1.Table("MyTable"))

it is possible to update a datasource with all the rows in MyTable.

What is the code to update a certain row in MyTable?

Thanks in advance

Geoff
 
Geoff,
DataAdapter.Update is overloaded to accept a DataSet, a DataTable, or an
array of DataRows, to update a single row I would put the single row in an
array by itself, then call Update with this array.

Something like:
Dim rows() As DataRow
' do something to fill the rows array with a single row
rows = dataSet1.Table("MyTable").Select(...)
dataAdaptor1.Update(rows)

For example I have a project that uses:

Dim rows() As DataRow
' do something to fill the rows array with a single row
rows = dataSet1.Table("MyTable").Select(Nothing, Nothing,
DataViewRowState.Added)
dataAdaptor1.Update(rows)


Which will cause all the added rows in my datatable to be deleted from the
database, without effecting the Deleted or Modified rows. I then do the
Modified rows, followed by the Deleted rows.

Hope this helps
Jay
 
Many thanks Jay

Jay B. Harlow said:
Geoff,
DataAdapter.Update is overloaded to accept a DataSet, a DataTable, or an
array of DataRows, to update a single row I would put the single row in an
array by itself, then call Update with this array.

Something like:
Dim rows() As DataRow
' do something to fill the rows array with a single row
rows = dataSet1.Table("MyTable").Select(...)
dataAdaptor1.Update(rows)

For example I have a project that uses:

Dim rows() As DataRow
' do something to fill the rows array with a single row
rows = dataSet1.Table("MyTable").Select(Nothing, Nothing,
DataViewRowState.Added)
dataAdaptor1.Update(rows)


Which will cause all the added rows in my datatable to be deleted from the
database, without effecting the Deleted or Modified rows. I then do the
Modified rows, followed by the Deleted rows.

Hope this helps
Jay
 
Doh!

I hate changing samples in mid stream. :-)
rows = dataSet1.Table("MyTable").Select(Nothing, Nothing,
DataViewRowState.Added)
Which will cause all the added rows in my datatable to be deleted from the
Should read "which will cause all the added rows in my datatable to be added
to the database".

Jay
 
Back
Top