Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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´t exist there before).

 

So my questions:

 

1- Am I right about my suspiction? (the update method doing a select before the insert)

2- Is there another way to insert the dataset in my database?

 

Thanks for any answers to these questions.

Posted

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.

  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...