Using the Data Form Wizard to Create a Windows Form phần 1
Thông tin tài liệu:
Nội dung trích xuất từ tài liệu:
Using the Data Form Wizard to Create a Windows Form phần 1Using the Data Form Wizard to Create a Windows FormIn this section, youll use the VS .NET Data Form Wizard to create a Windowsapplication that accesses both the Customers and Orders tables. The Orders table containsrows that represent orders placed by the customers.The rows in the Orders table are related to the rows in the Customers table through aforeign key: The Orders table contains a column named CustomerID that is a foreign keyto the CustomerID column of the Customers table (CustomerID is the primary key for theCustomers table). The use of the foreign key defines a parent-child relationship betweenthe Customers and Orders tables.The form youll create will display a row from the Customers table, along with anyrelated rows from the Orders table. To give you a clear idea of the final goal, Figure 6.17shows the completed form up and running. Notice that the top part of the form shows thedetails for the row from the Customers table where the CustomerID is ALFKI; the bottompart of the form contains a DataGrid control that displays the rows from the Orders tablefor that customer. When you move to the next row in the Customers table, the rows fromthe Orders table for that customer are automatically displayed in the DataGrid.Figure 6.17: The running formPerform these steps to begin build the form: 1. Select File ➣ New Project. 2. In the New Project dialog box, select Empty Project, and enter DataFormWindowsApplication in the Name field. Because youll be adding a new form to your new application shortly, theres no need to have VS .NET generate the usual blank form for you; thats why youre creating an empty project. 3. Click OK to continue. VS .NET will create a new empty project for you.Next, youll use the Data Form Wizard to create a form that accesses the Customers andOrders tables in the Northwind database: 1. Select Project ➣ Add New Item. 2. Select Data Form Wizard from the Templates section on the right, enter the Name of the form as MyDataForm.cs, and click Open (see Figure 6.18). Youll then see the welcome page for the Data Form Wizard. Figure 6.18: Adding a data form using the Data Form Wizard 3. Click the Next button to proceed. 4. Now you enter the DataSet object you want to use in your form. You can pick an existing DataSet, or you can create a new one. Because this is a new project, youll be creating a new DataSet. Enter myDataSet as the name for your DataSet, as shown in Figure 6.19. Figure 6.19: Entering the name of the new DataSet5. Click the Next button to go to the next step.6. You must now choose a data connection to access the database. You can pick an existing connection, or you can create a new one. Select your connection, as shown in Figure 6.20-of course, your connection name will be different. Figure 6.20: Choosing the data connection7. Click the Next button to continue.8. You now log in to the database by specifying the password for the database user. You used the sa user when creating the database connection earlier, and you therefore need to reenter the password for that user, as shown in Figure 6.21. Figure 6.21: Logging in to the SQL Server Northwind database 9. Click the OK button to proceed.You now select the database tables or views you want to use in your form. The area onthe bottom left of the dialog box shows the tables and views you can access using yourform. The area on the bottom right shows the tables and views youve added. You add atable or view to your form by selecting it from the area on the left and clicking the right-arrow button.Tip You can also double-click on the table or view to add them to your form.When you do this, the table or view moves to the right, indicating that youve selectedthem for use in your form. If you decide you dont want to use a table or view, you canunselect them using the left-arrow button. You can also double-click the table or view tounselect them. Select the Customers and Orders tables, as shown in Figure 6.22. Click theNext button to proceed.Figure 6.22: Selecting the Customers and Orders tables for use in the formBecause you selected two tables-Customers and Orders-your next step is to define arelationship between those tables. This relationship is used in your form to synchronizenavigation between the rows in the Customers table with the rows in the Orders table:When you move to a new row in the Customers table, the rows from the Orders table willbe displayed in your form. Set the following in the dialog box (as shown in Figure 6.23): 1. Enter myRelationship in the Name field. 2. Select Customers as the parent table. 3. Select Orders as the child table. 4. Select CustomerID as the key for each table. Warning To add the relatio ...
Tìm kiếm theo từ khóa liên quan:
kĩ thuật lập trình công nghệ thông tin lập trình ngôn ngữ lập trình C Shark C# sybex - c.sharp database programming Using the Data Form Wizard to Create a Windows Form phần 1Gợi ý tài liệu liên quan:
-
52 trang 431 1 0
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 318 0 0 -
74 trang 302 0 0
-
96 trang 296 0 0
-
Báo cáo thực tập thực tế: Nghiên cứu và xây dựng website bằng Wordpress
24 trang 289 0 0 -
Đồ án tốt nghiệp: Xây dựng ứng dụng di động android quản lý khách hàng cắt tóc
81 trang 283 0 0 -
EBay - Internet và câu chuyện thần kỳ: Phần 1
143 trang 277 0 0 -
Giáo trình Lập trình hướng đối tượng: Phần 2
154 trang 276 0 0 -
Tài liệu dạy học môn Tin học trong chương trình đào tạo trình độ cao đẳng
348 trang 269 1 0 -
Tài liệu hướng dẫn sử dụng thư điện tử tài nguyên và môi trường
72 trang 267 0 0 -
Bài thuyết trình Ngôn ngữ lập trình: Hệ điều hành Window Mobile
30 trang 267 0 0 -
Kỹ thuật lập trình trên Visual Basic 2005
148 trang 266 0 0 -
64 trang 264 0 0
-
Bài giảng An toàn và bảo mật thông tin - Trường đại học Thương Mại
31 trang 255 0 0 -
Giáo trình Lập trình cơ bản với C++: Phần 1
77 trang 232 0 0 -
47 trang 231 0 0
-
Bài giảng Một số hướng nghiên cứu và ứng dụng - Lê Thanh Hương
13 trang 226 0 0 -
Giáo trình Hệ điều hành: Phần 2
53 trang 221 0 0 -
Giáo án Tin học lớp 11 (Trọn bộ cả năm)
125 trang 218 1 0 -
LUẬN VĂN: TÌM HIỂU PHƯƠNG PHÁP HỌC TÍCH CỰC VÀ ỨNG DỤNG CHO BÀI TOÁN LỌC THƯ RÁC
65 trang 216 0 0