none
Which of these 2 options is more efficient in ADO.NET RRS feed

  • Question

  • As part of an application, I use a SqlDataAdapter to fill a Data Set.  For example let's say it now has 100 rows in it.

    Next, I loop over these rows and with each one gather some information and do some actions in a 3rd party system based on this data.  For only 1 of these records I will need to do an update back in the original table that I queried it from.  If I take this table that's got 100 records in it with only 1 updated and pass it to a method that creates a SqlCommandBuilder, does a GetUpdateCommand() and then updates the Adapter and accepts the changes, will it just write the 1 record back to the database or will it rewrite all 100?

    If it rewrites all 100 then would it be more efficient for me to requery the original db, and just get the 1 record in a Data Set that needs to be changed and then go through the process to make the change and update the source table?

    Thanks in advance.
    Monday, February 22, 2010 10:21 PM

Answers

  • The data adapter examines the DataRow.RowState property.  It will only submit the rows where the RowState indicates that there are changes.  (That is, RowState != DataRowState.Unchanged.)

    The Update method of the data adapter also has an overload which takes a DataRow[] (array) in case you need fine control over what exactly is submitted.

    If you would like to observe what is actually submitted to the server, use the SQL Server Profiler tool.

    Tuesday, February 23, 2010 12:48 AM

All replies

  • The data adapter examines the DataRow.RowState property.  It will only submit the rows where the RowState indicates that there are changes.  (That is, RowState != DataRowState.Unchanged.)

    The Update method of the data adapter also has an overload which takes a DataRow[] (array) in case you need fine control over what exactly is submitted.

    If you would like to observe what is actually submitted to the server, use the SQL Server Profiler tool.

    Tuesday, February 23, 2010 12:48 AM
  • I sort of assumed that it would do something like that, but didn't know for sure.

    Thanks for your help.
    Tuesday, February 23, 2010 2:35 AM