TAILIEUCHUNG - Performing a SQL SELECT Statement and Storing the Rows Locally phần 1

Performing a SQL SELECT Statement and Storing the Rows Locally In the example featured in this section, you'll see how to connect to the SQL Server | Performing a SQL SELECT Statement and Storing the Rows Locally In the example featured in this section you ll see how to connect to the SQL Server Northwind database and perform a SQL SELECT statement to retrieve the CustomerlD CompanyName ContactName and Address columns for the first 10 rows from the Customers table. These rows are stored in a DataSet object. Note Since I ll be using a SQL Server database I ll use the SQL Server managed provider classes in the example. Outlining the Procedure You can use the following steps to retrieve the rows into a DataSet object 1. Formulate a string containing the details of the database connection. 2. Create a SqlConnection object to connect to the database passing the connection string to the constructor. 3. Formulate a string containing a SELECT statement to retrieve the columns for the rows from the Customers table. 4. Create a SqlCommand object to hold the SELECT statement. 5. Set the CommandText property of the SqlCommand object to the SELECT string. 6. Create a SqlDataAdapter object. 7. Set the SelectCommand property of the SqlAdapter object to the SqlCommand object. 8. Create a DataSet object to store the results of the SELECT statement. 9. Open the database connection using the Open method of the SqlConnection object. 10. Call the Fill method of the SqlDataAdapter object to retrieve the rows from the table storing the rows locally in a DataTable of the DataSet object. 11. Close the database connection using the Close method of the SqlConnection object created in step 1. 12. Get the DataTable object from the DataSet object. 13. Display the columns for each row in the DataTable using a DataRow object to access each row in the DataTable. In the following sections you ll learn the details of these steps and see example code. Step 1 Formulate a String Containing the Details of the Database Connection When connecting to a SQL Server database your string must specify the following The name of the computer on which SQL .

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.