Using the Data Form Wizard to Create a Windows Form phần 2
Số trang: 7
Loại file: pdf
Dung lượng: 42.06 KB
Lượt xem: 11
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Figure 6.23: Creating a relationship between two tables Note Remember: Youre unselecting these columns, so you uncheck the columns for the Orders table
Nội dung trích xuất từ tài liệu:
Using the Data Form Wizard to Create a Windows Form phần 2Figure 6.23: Creating a relationship between two tablesNote Remember: Youre unselecting these columns, so you uncheck the columns for the Orders table.Figure 6.24 shows the completed dialog box with the selected columns to display fromeach table.Figure 6.24: Selecting the columns to display from each table 8. Click the Next button to proceed. 9. Select the display style for the rows (also known as records) in the parent table that are displayed in your form. You can display the rows in a grid, or you can display each column using a separate control. Youll use a separate control for the columns, so select the Single Record in individual controls radio button. The other check boxes in the dialog box allow you pick the controls you want to add to your form. These controls affect the rows in the master table, and you can add the following controls to your form: Note In this example, the parent table is the Customers table, and the child table is the Orders table. The rows for the child table are displayed in a DataGrid control. o Cancel All The Cancel All button allows you to undo any changes youve made to the current row. o Add The Add button allows you to add a new row. o Delete The Delete button allows you to delete the current row. o Cancel The Cancel button allows you to cancel a change made to the current row. o Navigation Controls The Navigation controls consist of four buttons that allow you to move to first row, the previous row, the next row, and the last row. An indicator is also displayed to show the current row.Figure 6.25 shows the completed dialog box.Figure 6.25: Choosing the display style 10. Youve now completed all the steps in the Data Form Wizard. Click the Finish button to create your form. VS .NET will now display the new form, as shown in Figure 6.26. Figure 6.26: The completed formThe managed provider objects in your form use the OLE DB classes contained in theSystem.Data.OleDb namespace-even though a SQL Server database is used. Theseobjects work with any OLE DB-compliant database. The code would be more efficient ifthe managed provider classes in the System.Data.SqlClient namespace were used instead;these classes are specifically for use with a SQL Server database. This is the price ofhaving the VS .NET wizard generate the code for you.In the next section, youll learn how the text-box controls in your form access thecolumns in the Customers table.Data BindingEach text-box control in the upper part of your form is bound to a column in theCustomers table using a process known as data binding. When a control is bound to acolumn in a DataSet object, the value for that column is displayed in the control throughthe Text property in the DataBindings group. The Text property in the DataBindingsgroup sets the text displayed in a control. To examine or set the data binding for acontrol, you select the control in the form designer and expand the DataBindingsproperties in the Properties window. Youll see these properties in the Data area of theProperties window.Next, youll see how the text box for the Customer ID is set. Select the text box to theright of the CustomerID label in your form; this text box is named editCustomerID. Makesure the DataBindings properties are expanded in the Properties window. Finally, clickthe drop-down list for the Text property to view the current column to which the text boxis bound. As you can see from Figure 6.27, editCustomerID is bound to the CustomerIDcolumn of the Customers table. This means that when you run the form and load datafrom the database, the CustomerID column value will be displayed in the editCustomerIDtext box.Figure 6.27: The editCustomerID text box is bound to the CustomerID columnIn the next section, youll add a label and a text-box control to display the City column inyour form.Adding Controls to the FormWhen you ran the Data Form Wizard earlier to create your form, youll recall that I toldyou to unselect the City column of the Customers table so that it didnt appear on yourform. I asked you to do this so that you can now see how to manually add a control andbind it to the City column. That way, you can see how to build your own forms thataccess the database.Follow these steps to add a label and a text box to your form: 1. Add a label below the Address label in your form. Set the Name property for your new label to lblCity. 2. Set the Text property for your label to City. 3. Next, add a text box below the editAddress text box. 4. Set the Name property for your new text box to editCity. 5. Remove the current text from the Text property so that ...
Nội dung trích xuất từ tài liệu:
Using the Data Form Wizard to Create a Windows Form phần 2Figure 6.23: Creating a relationship between two tablesNote Remember: Youre unselecting these columns, so you uncheck the columns for the Orders table.Figure 6.24 shows the completed dialog box with the selected columns to display fromeach table.Figure 6.24: Selecting the columns to display from each table 8. Click the Next button to proceed. 9. Select the display style for the rows (also known as records) in the parent table that are displayed in your form. You can display the rows in a grid, or you can display each column using a separate control. Youll use a separate control for the columns, so select the Single Record in individual controls radio button. The other check boxes in the dialog box allow you pick the controls you want to add to your form. These controls affect the rows in the master table, and you can add the following controls to your form: Note In this example, the parent table is the Customers table, and the child table is the Orders table. The rows for the child table are displayed in a DataGrid control. o Cancel All The Cancel All button allows you to undo any changes youve made to the current row. o Add The Add button allows you to add a new row. o Delete The Delete button allows you to delete the current row. o Cancel The Cancel button allows you to cancel a change made to the current row. o Navigation Controls The Navigation controls consist of four buttons that allow you to move to first row, the previous row, the next row, and the last row. An indicator is also displayed to show the current row.Figure 6.25 shows the completed dialog box.Figure 6.25: Choosing the display style 10. Youve now completed all the steps in the Data Form Wizard. Click the Finish button to create your form. VS .NET will now display the new form, as shown in Figure 6.26. Figure 6.26: The completed formThe managed provider objects in your form use the OLE DB classes contained in theSystem.Data.OleDb namespace-even though a SQL Server database is used. Theseobjects work with any OLE DB-compliant database. The code would be more efficient ifthe managed provider classes in the System.Data.SqlClient namespace were used instead;these classes are specifically for use with a SQL Server database. This is the price ofhaving the VS .NET wizard generate the code for you.In the next section, youll learn how the text-box controls in your form access thecolumns in the Customers table.Data BindingEach text-box control in the upper part of your form is bound to a column in theCustomers table using a process known as data binding. When a control is bound to acolumn in a DataSet object, the value for that column is displayed in the control throughthe Text property in the DataBindings group. The Text property in the DataBindingsgroup sets the text displayed in a control. To examine or set the data binding for acontrol, you select the control in the form designer and expand the DataBindingsproperties in the Properties window. Youll see these properties in the Data area of theProperties window.Next, youll see how the text box for the Customer ID is set. Select the text box to theright of the CustomerID label in your form; this text box is named editCustomerID. Makesure the DataBindings properties are expanded in the Properties window. Finally, clickthe drop-down list for the Text property to view the current column to which the text boxis bound. As you can see from Figure 6.27, editCustomerID is bound to the CustomerIDcolumn of the Customers table. This means that when you run the form and load datafrom the database, the CustomerID column value will be displayed in the editCustomerIDtext box.Figure 6.27: The editCustomerID text box is bound to the CustomerID columnIn the next section, youll add a label and a text-box control to display the City column inyour form.Adding Controls to the FormWhen you ran the Data Form Wizard earlier to create your form, youll recall that I toldyou to unselect the City column of the Customers table so that it didnt appear on yourform. I asked you to do this so that you can now see how to manually add a control andbind it to the City column. That way, you can see how to build your own forms thataccess the database.Follow these steps to add a label and a text box to your form: 1. Add a label below the Address label in your form. Set the Name property for your new label to lblCity. 2. Set the Text property for your label to City. 3. Next, add a text box below the editAddress text box. 4. Set the Name property for your new text box to editCity. 5. Remove the current text from the Text property so that ...
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 2Gợi ý tài liệu liên quan:
-
52 trang 429 1 0
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 311 0 0 -
74 trang 294 0 0
-
96 trang 290 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 288 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 278 0 0 -
EBay - Internet và câu chuyện thần kỳ: Phần 1
143 trang 272 0 0 -
Giáo trình Lập trình hướng đối tượng: Phần 2
154 trang 271 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 -
Bài thuyết trình Ngôn ngữ lập trình: Hệ điều hành Window Mobile
30 trang 262 0 0