I am a newbie in VB.NET windows application development. Now I am referring an already developed application. In my reference project every data update is using a DataAdapter, first loading the data in the adapter then creating a new row that updates adapter. So, this method first fetches data then updates data. If we are using direct SQL commands there is only one database insert/update statement. Is there significant impact in between these two methods?
2 Answers
Is there significant impact in between these two methods?
That is a very general question, so the general answer is "It depends...". The overhead of creating and filling a DataAdapter will cost you something, but whether or not that is a significant cost will depend on factors like...
how much data is in the table(s) you are updating
how much information you are pulling into the DataAdapter
whether the database file is on a local drive or a network share
...and (perhaps) many other factors. The only way for you to know if there is a significant performance difference between the two approaches in your particular circumstances would be for you to run some tests and compare the results.
2 Comments
The latter option will be on the whole be faster, to my knowledge. The DataAdapter will as you suggest query for the data and load it into memory, before making any required updates. I would be extremely surprised however, if the DataAdapter updated all rows regardless of whether the row has changed - I should expect that it will only send the required SQL to the DBMS.
Running an update statement via SqlCommand circumvents querying for and loading the data, and dependent on your query will probably make the update to the DB itself in roundabout the same way.
The decision between the two depends entirely on context.