TAILIEUCHUNG - Updating a Database Using a DataSet

Cập nhật một cơ sở dữ liệu Sử dụng một DataSet Trong các bài tập cho đến nay trong chương này, bạn đã thấy làm thế nào để lấy dữ liệu từ cơ sở dữ liệu. Bây giờ là lúc để cho bạn thấy làm thế nào để cập nhật dữ liệu | Updating a Database Using a DataSet In the exercises so far in this chapter you have seen how to fetch data from a database. Now it s time to show you how to update data. First however we need to consider some potential problems and how using a DataSet can overcome them. Databases are intended to support multiple concurrent users but resources such as the number of concurrent connections allowed might be limited. In an application that fetches and displays data you never know quite how long the user will be browsing the data and it is not a good practice to keep a database connection open for an extended period of time. Instead a better approach is to connect to the database fetch the data into a DataSet object and then disconnect again. The user can browse the data in the DataSet and make any changes required. After the user finishes the program can reconnect to the database and submit any changes. Of course there are complications that you need to consider such as what happens if two users have queried and updated the same data changing it to different values. Which value should be stored in the database We will come back to this problem shortly. Managing Connections In earlier exercises you have seen that when you define a DataSet you can specify a connection to use for communicating with the database. This information is embedded into the TableAdapter used to retrieve the data and fill the DataSet. When you execute the Fill or GetData methods the code generated by Visual Studio 2005 examines the state of the connection first. If the connection to be used is already open it is used to retrieve the data and is left open at the end of the operation. If the connection is closed the Fill and GetData methods open it fetch the data and then close it again. The DataSet in this case is referred to as a disconnected DataSet as it doesn t maintain an active connection to the database. Disconnected DataSet objects act as a data cache in applications. You can modify the .

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.