1. Trang chủ
  2. » Công Nghệ Thông Tin

Tài liệu Creating a DataSet Object Using Visual Studio .NET docx

3 351 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Creating a DataSet object using Visual Studio .NET
Thể loại Tutorial
Định dạng
Số trang 3
Dung lượng 42,35 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Creating a DataSet Object Using Visual Studio .NET In this section, you'll learn how to create a DataSet using Visual Studio .NET.. Note You'll find a completed VS .NET example project f

Trang 1

Creating a DataSet Object Using Visual Studio NET

In this section, you'll learn how to create a DataSet using Visual Studio NET

Note You'll find a completed VS NET example project for this section in the DataSet

directory You can open this project in VS NET by selecting File ➣ Open ➣

Project and opening the WindowsApplication4.csproj file You can also follow

along with the instructions in this section by continuing to modify the copy of the

DataReader project you used in the previous section

If you're following along with these instructions, open your copy of the DataReader project you modified in the previous section, and open Form1.cs by double-clicking it in the Solution Explorer window To create a DataSet object, you can perform either one of the following:

• Drag a DataSet object from the Data tab of the Toolbox to your form, and add code to your form to fill it using the Fill() method of a DataAdapter object

• Click the Generate Dataset link at the bottom of the Properties window of your DataAdapter You can see this link in Figure 10.13

You'll use the second step, so go ahead and click the Generate Dataset link The Generate Dataset dialog box is then displayed, as shown in Figure 10.14

Figure 10.14: The Generate Dataset dialog box

Click the OK button to continue The new DataSet object named dataSet11 is added to the tray beneath your form, as shown in Figure 10.15

Trang 2

Figure 10.15: The new DataSet object in the tray

Your next step is to set the Form1_Load() method of your form as follows:

private void Form1_Load(object sender, System.EventArgs e)

{

sqlConnection1.Open();

sqlDataAdapter1.Fill(dataSet11, "Products");

sqlConnection1.Close();

System.Data.DataTable myDataTable =

dataSet11.Tables["Products"];

foreach (System.Data.DataRow myDataRow in myDataTable.Rows)

{

listView1.Items.Add(myDataRow["ProductID"].ToString());

listView1.Items.Add(myDataRow["ProductName"].ToString());

listView1.Items.Add(myDataRow["UnitPrice"].ToString());

}

}

Note Remember, to view the code of your form, you select View ➣ Code You then

replace the Form1_Load() method with the previous code

You can then compile and run your form Figure 10.16 shows the running form

Trang 3

Figure 10.16: The running form

Ngày đăng: 21/01/2014, 07:20

TỪ KHÓA LIÊN QUAN