Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (33.52 KB, 3 trang )
Creating a DataView Using Visual Studio .NET
In this section, you'll 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.