Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Lưu ý Tại thời điểm này, nút Delete trên mẫu CustomerEditor không hoạt động. Ví dụ xuất hiện sau đó trong chương này trên trang 283 cho biết thêm các mã cần thiết để kích hoạt tính năng loại bỏ khách hàng. | 276 Microsoft ADO.NET 4 Step by Step Note At this point the Delete button on the CustomerEditor form does not work. The example that appears later in this chapter on page 283 adds the necessary code to enable the customer removal feature. Modifying a Database Through Entity Objects Visual Basic 1. Open the Chapter 16 VB project from the installed samples folder. The project includes Windows.Forms classes named CustomerEditor and CustomerDetail which let a user modify records in the sample database s Customer table. 2. Open the source code view for the CustomerEditor form. Locate the GetConnectionString function this is a routine that uses a SqlConnectionStringBuilder to create a valid connection string to the sample database. It currently includes the following statements sqlPortion.DataSource local SQLExpress sqlPortion.InitialCatalog StepSample sqlPortion.IntegratedSecurity True Adjust these statements as needed to provide access to your own test database. 3. Open the source code view for the CustomerDetail form. Locate the SaveFormData function. This routine updates an entity s properties with data supplied by the user. Just after the Update the individual fields comment add the following statements toUpdate.FullName CustomerName.Text.Trim If Address1.Text.Trim.Length 0 Then _ toUpdate.Address1 Address1.Text.Trim Else _ toUpdate.Address1 Nothing If Address2.Text.Trim.Length 0 Then _ toUpdate.Address2 Address2.Text.Trim Else _ toUpdate.Address2 Nothing If CityName.Text.Trim.Length 0 Then _ toUpdate.City CityName.Text.Trim Else _ Chapter 16 Understanding Entities Through Objects 277 toUpdate.City Nothing If ItemData.GetltemData StateName.Selectedltem -1 Then _ toUpdate.StateRegion ItemData.GetItemData StateName.SelectedItem Else toUpdate.StateRegion Nothing If PostalCode.Text.Trim.Length 0 Then _ toUpdate.PostalCode PostalCode.Text.Trim Else _ toUpdate.PostalCode Nothing If PhoneNumber.Text.Trim.Length 0 Then _ toUpdate.PhoneNumber PhoneNumber.Text.Trim Else _ .