How SqlDataAdapter works internally?

Posted by tigrou on Stack Overflow See other posts from Stack Overflow or by tigrou
Published on 2012-12-19T23:02:05Z Indexed on 2012/12/19 23:02 UTC
Read the original article Hit count: 158

I wonder how SqlDataAdapter works internally, especially when using UpdateCommand for updating a huge DataTable (since it's usually a lot faster that just sending sql statements from a loop).

Here is some idea I have in mind :

  • It creates a prepared sql statement (using SqlCommand.Prepare()) with CommandText filled and sql parameters initialized with correct sql types. Then, it loops on datarows that need to be updated, and for each record, it updates parameters values, and call SqlCommand.ExecuteNonQuery().
  • It creates a bunch of SqlCommand objects with everything filled inside (CommandText and sql parameters). Several SqlCommands at once are then batched to the server (depending of UpdateBatchSize).
  • It uses some special, low level or undocumented sql driver instructions that allow to perform an update on several rows in a effecient way (rows to update would need to be provided using a special data format and a the same sql query (UpdateCommand here) would be executed against each of these rows).

© Stack Overflow or respective owner

Related posts about c#

Related posts about sql-server