SqlDataAdapter question

pajaro9

New member
Joined
May 23, 2006
Messages
2
Hello all,

I have this question or doubt about how SqlDataAdapter operates:

I have a DataSet which I have filled from a plain text file.
I fill a SqlDataAdapter with this DataSet.
I execute the SqlDataAdapter.Update method so the dataSet is inserted in a SQL Server Data base.

This is all working fine, now, what I suspect from a log sent by the DB administrator is that the SqlDataAdapter.Update operation is executing a Select command first, returning all the records from the table before inserting the records in the DataSet!

All the records in the dataSet are new to the table in the data base and sholud be inserted without checking wheter they are to be updated (since they didn
 
Well, I am using the CommandBuilder, so this is what is causing the execution of the Select statment:

"The DbCommandBuilder must execute the SelectCommand in order to return the metadata necessary to construct the INSERT, UPDATE, and DELETE SQL commands. As a result, an extra trip to the data source is necessary, and this can hinder performance. To achieve optimal performance, specify your commands explicitly rather than using the DbCommandBuilder." http://msdn2.microsoft.com/en-US/library/tf579hcz.aspx

The Select command is heavy, so I do not want that extra trip. I am gonna fix it.
 
Generally speaking it is far more reliable to create the insert, update and delete commands yourself rather than relying on the CommandBuilder to do it for you.
As well as the potential performance issues the CommandBuilder will often generate very simplistic code whereas a hand written version would be able to include error checking / validation etc.
 
Back
Top