Updating database using dataadapter
The Sql Data Adapter opens a connection only when required and closes it as soon as it has performed its task.For example, the Sql Data Adapter performs the following tasks when filling a Data Set with data: In between the Fill and Update operations, data source connections are closed and you are free to read and write data with the Data Set as you need.A couple scenarios illustrate why you would want to work with disconnected data: people working without network connectivity and making Web sites more scalable.Consider salespeople who need customer data as they travel.In Lesson 3, we discussed a fully connected mode of operation for interacting with a data source by using the Sql Command object.In Lesson 4, we learned how to read data quickly an let go of the connection with the Sql Data Reader.These are the mechanics of working with disconnected data.Because the applications hold on to connections only when necessary, the application becomes more scalable.
As indicated earlier, the Sql Data Adapter contains all of the commands necessary to interact with the data source.
Every request for the page checks the cache and loads the data if it isn’t there or just pulls the data out of the cache and displays it.
This avoids a trip to the database, making your application more efficient.
This requires a new connection for each page load, which will hurt scalability as the number of users increases.
One way to relieve this is to use a Data Set that is updated one time and stored in the cache.The code showed how to specify the select statement, but didn’t show the insert, update, and delete statements.These are added to the Sql Data Adapter after it is instantiated.The Sql Data Adapter holds the SQL commands and connection object for reading and writing data.