Creating a DataSet Object Using Visual Studio .NET
Số trang: 3
Loại file: pdf
Dung lượng: 0.00 B
Lượt xem: 10
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 DataSet Object Using Visual Studio .NET In this section, youll learn how to create a DataSet using Visual Studio .NET. Note Youll find a completed VS .NET
Nội dung trích xuất từ tài liệu:
Creating a DataSet Object Using Visual Studio .NETCreating a DataSet Object Using Visual Studio .NETIn this section, youll learn how to create a DataSet using Visual Studio .NET.Note Youll 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 youre following along with these instructions, open your copy of the DataReaderproject you modified in the previous section, and open Form1.cs by double-clicking it inthe Solution Explorer window. To create a DataSet object, you can perform either one ofthe 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.Youll use the second step, so go ahead and click the Generate Dataset link. The GenerateDataset dialog box is then displayed, as shown in Figure 10.14.Figure 10.14: The Generate Dataset dialog boxClick the OK button to continue. The new DataSet object named dataSet11 is added tothe tray beneath your form, as shown in Figure 10.15.Figure 10.15: The new DataSet object in the trayYour 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.Figure 10.16: The running form
Nội dung trích xuất từ tài liệu:
Creating a DataSet Object Using Visual Studio .NETCreating a DataSet Object Using Visual Studio .NETIn this section, youll learn how to create a DataSet using Visual Studio .NET.Note Youll 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 youre following along with these instructions, open your copy of the DataReaderproject you modified in the previous section, and open Form1.cs by double-clicking it inthe Solution Explorer window. To create a DataSet object, you can perform either one ofthe 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.Youll use the second step, so go ahead and click the Generate Dataset link. The GenerateDataset dialog box is then displayed, as shown in Figure 10.14.Figure 10.14: The Generate Dataset dialog boxClick the OK button to continue. The new DataSet object named dataSet11 is added tothe tray beneath your form, as shown in Figure 10.15.Figure 10.15: The new DataSet object in the trayYour 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.Figure 10.16: 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 DataSet Object 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