Defining a Relationship Using Visual Studio .NET
Số trang: 5
Loại file: pdf
Dung lượng: 36.57 KB
Lượt xem: 9
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:
Defining a Relationship Using Visual Studio .NET In this section, youll see how to create a Windows application in Visual Studio .NET (VS .NET)
Nội dung trích xuất từ tài liệu:
Defining a Relationship Using Visual Studio .NETDefining a Relationship Using Visual Studio .NETIn this section, youll see how to create a Windows application in Visual Studio .NET(VS .NET) with a DataSet containing two DataTable objects. These DataTable objectswill reference the Customers and Orders database tables. Youll then learn how to definea relationship between the two DataTable objects in the XML schema.Create the Windows ApplicationPerform the following steps to create the Windows application: 1. Open VS .NET and select File ➣ New ➣ Project and create a new Windows Application. Enter the name of the project as DataRelation, as shown in Figure 12.2. Figure 12.2: Creating the Windows application 2. Click the OK button to continue. 3. Open Server Explorer and connect to the Northwind database using the connection you used in the previous chapters. You can open Server Explorer by selecting View ➣ Server Explorer. Expand the Tables node in the tree and select both the Customers and Orders tables by Ctrl +left-clicking each table, as shown in Figure 12.3. Figure 12.3: Selecting both the Customers and Orders tables from Server Explorer 4. Drag the Customers and Orders tables to your form. VS .NET then creates three objects in the tray beneath your form. These objects are named sqlConnection1 (used to access the Northwind database), sqlDataAdapter1 (used to handle access to the Customers table), and sqlDataAdapter2 (used to handle access to the Orders table). These objects are shown in Figure 12.4. Figure 12.4: The new objects in the tray beneath the form 5. Next, you need a DataSet object that contains DataTable objects to store the rows from the Customers and Orders tables. To create a DataSet object, click your blank form and then click the Generate Dataset link at the bottom of the Properties window for the form shown earlier in Figure 12.4.This displays the Generate Dataset dialog box, as shown in Figure 12.5. Leave all thesettings in this dialog in their default state.Figure 12.5: The Generate Dataset dialog boxNotice that a new DataSet is to be created, and the Customers and Orders tables are usedin the new DataSet. The new DataSet will also be added to the designer, as indicated bythe check box in the dialog box. Click the OK button to continue.A new DataSet named dataSet11 will be added to the tray beneath your form.Adding a Relation to the XML Schema of the DataSetPerform the following steps to add a relation to the XML schema of your DataSet: 1. Select your new DataSet in the tray and click the View Schema link in the Properties window. This displays the Schema Editor, as shown in Figure 12.6. Figure 12.6: The Schema Editor 2. Drag a relation from the XML Schema tab in the Toolbox to the Orders table entity. This opens the Edit Relation dialog box, as shown in Figure 12.7. Figure 12.7: The Edit Relation dialog boxAs you can see from Figure 12.7, you can set the parent and child tables, the primary keyand foreign keys, along with other details for the relation. 3. Leave the settings in the Edit Relation dialog box in their default state and click the OK button to continue.This adds the new relation to the Customers and Orders entities in the XML schema. Youcan click the diamond between the Customers and Orders entities to view the propertiesof the relation, as shown in Figure 12.8.Figure 12.8: The properties of the new relationNote You can add a relation to a strongly typed DataSet in the same way as described in this section.
Nội dung trích xuất từ tài liệu:
Defining a Relationship Using Visual Studio .NETDefining a Relationship Using Visual Studio .NETIn this section, youll see how to create a Windows application in Visual Studio .NET(VS .NET) with a DataSet containing two DataTable objects. These DataTable objectswill reference the Customers and Orders database tables. Youll then learn how to definea relationship between the two DataTable objects in the XML schema.Create the Windows ApplicationPerform the following steps to create the Windows application: 1. Open VS .NET and select File ➣ New ➣ Project and create a new Windows Application. Enter the name of the project as DataRelation, as shown in Figure 12.2. Figure 12.2: Creating the Windows application 2. Click the OK button to continue. 3. Open Server Explorer and connect to the Northwind database using the connection you used in the previous chapters. You can open Server Explorer by selecting View ➣ Server Explorer. Expand the Tables node in the tree and select both the Customers and Orders tables by Ctrl +left-clicking each table, as shown in Figure 12.3. Figure 12.3: Selecting both the Customers and Orders tables from Server Explorer 4. Drag the Customers and Orders tables to your form. VS .NET then creates three objects in the tray beneath your form. These objects are named sqlConnection1 (used to access the Northwind database), sqlDataAdapter1 (used to handle access to the Customers table), and sqlDataAdapter2 (used to handle access to the Orders table). These objects are shown in Figure 12.4. Figure 12.4: The new objects in the tray beneath the form 5. Next, you need a DataSet object that contains DataTable objects to store the rows from the Customers and Orders tables. To create a DataSet object, click your blank form and then click the Generate Dataset link at the bottom of the Properties window for the form shown earlier in Figure 12.4.This displays the Generate Dataset dialog box, as shown in Figure 12.5. Leave all thesettings in this dialog in their default state.Figure 12.5: The Generate Dataset dialog boxNotice that a new DataSet is to be created, and the Customers and Orders tables are usedin the new DataSet. The new DataSet will also be added to the designer, as indicated bythe check box in the dialog box. Click the OK button to continue.A new DataSet named dataSet11 will be added to the tray beneath your form.Adding a Relation to the XML Schema of the DataSetPerform the following steps to add a relation to the XML schema of your DataSet: 1. Select your new DataSet in the tray and click the View Schema link in the Properties window. This displays the Schema Editor, as shown in Figure 12.6. Figure 12.6: The Schema Editor 2. Drag a relation from the XML Schema tab in the Toolbox to the Orders table entity. This opens the Edit Relation dialog box, as shown in Figure 12.7. Figure 12.7: The Edit Relation dialog boxAs you can see from Figure 12.7, you can set the parent and child tables, the primary keyand foreign keys, along with other details for the relation. 3. Leave the settings in the Edit Relation dialog box in their default state and click the OK button to continue.This adds the new relation to the Customers and Orders entities in the XML schema. Youcan click the diamond between the Customers and Orders entities to view the propertiesof the relation, as shown in Figure 12.8.Figure 12.8: The properties of the new relationNote You can add a relation to a strongly typed DataSet in the same way as described in this section.
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 Defining a Relationship Using Visual Studio .NETGợi ý tài liệu liên quan:
-
52 trang 413 1 0
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 293 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 287 0 0 -
74 trang 277 0 0
-
96 trang 277 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 265 1 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 262 0 0 -
Giáo trình Lập trình hướng đối tượng: Phần 2
154 trang 258 0 0 -
EBay - Internet và câu chuyện thần kỳ: Phần 1
143 trang 253 0 0 -
Kỹ thuật lập trình trên Visual Basic 2005
148 trang 247 0 0