Creating a DataView Using Visual Studio .NET
Số trang: 3
Loại file: pdf
Dung lượng: 33.52 KB
Lượt xem: 7
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:
Creating a DataView Using Visual Studio .NET In this section, youll learn how to create a DataView using Visual Studio .NET (VS .NET)
Nội dung trích xuất từ tài liệu:
Creating a DataView Using Visual Studio .NETCreating a DataView Using Visual Studio .NETIn this section, youll learn how to create a DataView using Visual Studio .NET (VS.NET). You can follow along with the steps described in this section: 1. Open VS .NET and create a new Windows application named myDataView. 2. Display Server Explorer, connect to your Northwind database, and drag the Customers table to your form. This creates a SqlConnection object named sqlConnection1 and a SqlDataAdapter object named sqlDataAdapter1. These objects are placed in the tray beneath your form. 3. Alter the ConnectionString property of sqlConnection1 to connect to your Northwind database. Remember to add a substring containing the password (pwd=sa, or similar). 4. Click on the sqlDataAdapter1 object in your form, and then click the Generate Dataset link at the bottom of the Properties window for sqlDataAdapter1. Accept the defaults in the dialog box, and click the OK button to create a DataSet object named dataSet11. 5. Drag a DataView object from the Data tab of the Toolbox to your form. This creates a DataView object named dataView1. 6. Set the Table property of your dataView1 object to dataSet11.Customers using the drop-down list to the right of the Table property; set the RowFilter property to Country=UK; and set the Sort property to CustomerID. See Figure 13.1. Figure 13.1: Setting the Properties of dataView1 7. Drag a DataGrid control from the Windows Forms tab of the Toolbox to your form. This creates a DataGrid object named dataGrid1. 8. Set the DataSource property of dataGrid1 to dataView1 using the drop-down list to the right of the DataSource property, as shown in Figure 13.2. This binds the data stored in dataView1 to dataGrid1 and allows dataGrid1 to access any data stored in dataView1. Figure 13.2: Setting the Properties of dataGrid1 9. Select View ➣ Code and set the Form1() method of your form to 10. public Form1() 11. { 12. // 13. // Required for Windows Form Designer support 14. // 15. InitializeComponent(); 16. 17. // call the Fill() method of sqlDataAdapter1 18. // to populate dataSet11 with a DataTable named 19. // Customers 20. sqlDataAdapter1.Fill(dataSet11, Customers); 21. }Compile and run your form by pressing Ctrl+F5. Figure 13.3 shows the running form.Notice that the information in the form comes from the DataView you created.Figure 13.3: The running form
Nội dung trích xuất từ tài liệu:
Creating a DataView Using Visual Studio .NETCreating a DataView Using Visual Studio .NETIn this section, youll learn how to create a DataView using Visual Studio .NET (VS.NET). You can follow along with the steps described in this section: 1. Open VS .NET and create a new Windows application named myDataView. 2. Display Server Explorer, connect to your Northwind database, and drag the Customers table to your form. This creates a SqlConnection object named sqlConnection1 and a SqlDataAdapter object named sqlDataAdapter1. These objects are placed in the tray beneath your form. 3. Alter the ConnectionString property of sqlConnection1 to connect to your Northwind database. Remember to add a substring containing the password (pwd=sa, or similar). 4. Click on the sqlDataAdapter1 object in your form, and then click the Generate Dataset link at the bottom of the Properties window for sqlDataAdapter1. Accept the defaults in the dialog box, and click the OK button to create a DataSet object named dataSet11. 5. Drag a DataView object from the Data tab of the Toolbox to your form. This creates a DataView object named dataView1. 6. Set the Table property of your dataView1 object to dataSet11.Customers using the drop-down list to the right of the Table property; set the RowFilter property to Country=UK; and set the Sort property to CustomerID. See Figure 13.1. Figure 13.1: Setting the Properties of dataView1 7. Drag a DataGrid control from the Windows Forms tab of the Toolbox to your form. This creates a DataGrid object named dataGrid1. 8. Set the DataSource property of dataGrid1 to dataView1 using the drop-down list to the right of the DataSource property, as shown in Figure 13.2. This binds the data stored in dataView1 to dataGrid1 and allows dataGrid1 to access any data stored in dataView1. Figure 13.2: Setting the Properties of dataGrid1 9. Select View ➣ Code and set the Form1() method of your form to 10. public Form1() 11. { 12. // 13. // Required for Windows Form Designer support 14. // 15. InitializeComponent(); 16. 17. // call the Fill() method of sqlDataAdapter1 18. // to populate dataSet11 with a DataTable named 19. // Customers 20. sqlDataAdapter1.Fill(dataSet11, Customers); 21. }Compile and run your form by pressing Ctrl+F5. Figure 13.3 shows the running form.Notice that the information in the form comes from the DataView you created.Figure 13.3: The running form
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 Creating a DataView Using Visual Studio .NETGợ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