tailieunhanh - Using a DataReader Object in Visual Studio .NET
Using a DataReader Object in Visual Studio .NET You can't visually create a DataReader object in Visual Studio .NET (VS .NET); you can only create them using program statements. | Using a DataReader Object in Visual Studio .NET You can t visually create a DataReader object in Visual Studio .NET VS .NET you can only create them using program statements. In this section you ll see how to create a SqlDataReader object and use it to retrieve the result set from a SqlCommand object which you saw how to create using VS .NET in the previous chapter. That SqlCommand object contained a SELECT statement that retrieved the CustomerID CompanyName and ContactName columns from the Customers table. You ll see how to execute this SELECT statement read the result set using the SqlDataReader object and display the result set in a ListView control. A ListView control allows you to view information laid out in a grid. Note You can either modify the MyDataReader project you created in the previous chapter or if you don t want to follow along with the instructions in this section you can simply open the completed VS .NET project contained in the DataReader directory. To open the completed project select File Open Project browse to the VS .NETprojects DataReader directory and open the file. If you are modifying your existing Windows application drag a ListView control to your form. Figure shows a form with a ListView control. Make sure the Name property of your ListView is set to listView1 this is the default name so you shouldn t have to change it . Figure Adding a ListView control to the form Warning If you opened the completed project you don t have to add a ListView controI it s already on the completed form. You will need to change the ConnectionString property of the sqlConnection1 object so that it connects to your SQL Server Northwind database. Once you ve set your ConnectionString you can run the form by selecting Debug Start Without Debugging. Next double-click an area on your form outside the ListView control. This causes VS .NET to display the code editor and you ll see the cursor positioned in the Form1_Load method .
đang nạp các trang xem trước