TAILIEUCHUNG - Professional Microsoft Smartphone Programming phần 4

Hình 14-13 trình bày cách bố trí đồ họa giao diện người dùng và các mục trình đơn. Nếu bạn kiểm tra các mã được tạo ra bởi Visual Studio 2005 trongKhi ném một ngoại lệ do người dùng định nghĩa, bạn có tùy chọn để sử dụng một trong những nhà xây dựng sẵn. | Data Access with SQL Server Mobile Integrated Security SSPI Inital Catalog myCourses SqlCommand sqlCmd SELECT studentID lastName FROM students sqlDataReader stuReader while 0 t 1 0 l In the preceding code a SQL connection is first created by specifying the connection string and invoking the Open method of the SqlConnection class. Then a SqlCommand object is instantiated to retrieve records in the studentID field and the lastName field from the table students. The results of the query are executed by the ExecuteReader method of the SqlCommand class and are passed to a sqlDataReader object. By iterating the sqlDataReader object with the Read method data can be retrieved row by row. To retrieve the data in disconnected mode a typical approach is to use a DataAdapater object to retrieve data from a data source and then populate the data to a DataSet object which can hold multiple data tables in memory. The following code snippet demonstrates how to perform the same function in disconnected mode using System using using . SqlConnection dbConn new SqlConnection Data Source localhost Integrated Security SSPI Inital Catalog myCourses string qStr SELECT studentID lastName FROM students SqlDataAdapter stuAdapter new SqlDataAdapter qStr dbConn DataSet stuSet new DataSet stuSet students for int i 0 i students . i int ID students .Rows i studentID string name students .Rows i lastName .ToString 0 t 1 ID name In the preceding example a SqlConnection object is first created. However you do not need to maintain an open connection to the database by calling the open method. Rather a sqlDataApapter object is 133 Chapter 6 created with the same SQL query command .

Đã 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.