Merge Method for Datasets Change Rowstate of Unchanged to changed or modified

  • Thread starter Thread starter certolnut
  • Start date Start date
C

certolnut

Hi all

I'm using the "Merge" method for datasets to append data from an external
excel spreadsheet into a Sql Server Table

The problem is that "Merge" method copies over the current RowState
(UNCHANGED)of the excel spreadsheet rows, so when I try to update the data
adapter for Sql Server, it won't update the database (The DataAdapter won't
process rows that are set as "Unchanged"

Is there a way to programatically change the rowstate to "Modified" or
"changed" or something that the Data Adapter can handle??

Any help would be hugely appreciated....
 
In .NET 1.1 and before, there is no way to do this. In order to get
around this, you would have to copy the rows one by one, adding a new row in
the new table when you copy it over. If you wanted to simulate an update,
you would have to call AcceptChanges on the row, and then set the value on a
column in the row to set the RowState to Modified.

In .NET 2.0, there is a SetAdded and a SetModified method on the DataRow
class which will allow you to change the state.

Hope this helps.
 
Hi Nicholas

Thanks, this is what I thought would have to happen, but I wanted it
confirmed

thanks again for the help!

Nicholas Paldino said:
In .NET 1.1 and before, there is no way to do this. In order to get
around this, you would have to copy the rows one by one, adding a new row in
the new table when you copy it over. If you wanted to simulate an update,
you would have to call AcceptChanges on the row, and then set the value on a
column in the row to set the RowState to Modified.

In .NET 2.0, there is a SetAdded and a SetModified method on the DataRow
class which will allow you to change the state.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

certolnut said:
Hi all

I'm using the "Merge" method for datasets to append data from an external
excel spreadsheet into a Sql Server Table

The problem is that "Merge" method copies over the current RowState
(UNCHANGED)of the excel spreadsheet rows, so when I try to update the data
adapter for Sql Server, it won't update the database (The DataAdapter
won't
process rows that are set as "Unchanged"

Is there a way to programatically change the rowstate to "Modified" or
"changed" or something that the Data Adapter can handle??

Any help would be hugely appreciated....
 
Back
Top