Đang chuẩn bị liên kết để tải về tài liệu:
Using ADO.NET Programmatically

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Sử dụng ADO.NET lập trình Trong tập tiếp theo của bài tập, bạn sẽ viết mã của riêng bạn để truy cập cơ sở dữ liệu hơn là kéo bảng từ cửa sổ các nguồn dữ liệu. | Using ADO.NET Programmatically In the next set of exercises you will write your own code to access the database rather than dragging tables from the Data Sources window. The aim of the exercise is to help you learn more about ADO.NET and understand the object model implemented by ADO.NET by programming it manually. In many cases this is what you will have to do in real life the drag-and-drop approach is fine for creating prototypes but on many occasions you will want more control over how data is retrieved and manipulated. The application you are going to create will generate a simple report displaying information about customers orders. The program will prompt the user for a CustomerlD and then display the orders for that customer. Connect to the database 1. Create a new project called ReportOrders by using the Console Application template. Save it in the Microsoft Press Visual CSharp Step By Step Chapter 23 folder in your My Documents folder. Click OK. 2. In the Solution Explorer change the name of Program.cs to Report.cs. Notice that the name of the Program class in the Code and Text Editor window changes to Report automatically. 3. In the Code And Text Editor window add the following statement under the using System.Text statement using System.Data.SqlClient The System.Data.SqlClient namespace contains the specialized ADO.NET classes used to gain access to SQL Server. 4. Locate the Main method of the Report class. Add the following statement that declares a SqlConnection object SqlConnection dataConnection new SqlConnection SqlConnection is a subclass of the ADO.NET Connection class. It is designed to handle connections to SQL Server databases only. 5. After the variable declaration add a try catch block to the Main method. All the code that you will write for gaining access to the database goes inside the try part of this block remember that you must be prepared to handle exceptions whenever you use a database. 6. try 7. 8. You will add your code here in a .

TÀI LIỆU LIÊN QUAN