CustomerID and Display

Using 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 | Using 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 and understand the object model implemented by 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 to . 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 statement using The namespace contains the specialized 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 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 .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU LIÊN QUAN
5    176    1
5    255    1
5    106    0
5    121    1
6    103    1
6    107    1
6    121    1
6    103    0
6    140    0
TÀI LIỆU MỚI ĐĂNG
Đã 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.