Developing Your First ADO.NET

Developing Your First Program In this section you'll plunge into programming and see a C# program that performs the following tasks: 1. 2. 3. 4. | Developing Your First Program In this section you ll plunge into programming and see a C program that performs the following tasks 1. Connects to the SQL Server Northwind database 2. Retrieves a row from the Customers table 3. Displays the columns from the row 4. Closes the database connection You ll be introduced to many concepts in this section that are fully explored in later chapters. Don t be too concerned about all the details of the concepts at this stage you ll learn those details in the later chapters. Listing shows the example program which is contained in the file . Listing illustrates how to 1. Connect to the SQL Server Northwind database. 2. Retrieve a row from the Customers table using a SQL SELECT statement. 3. Display the columns from the row. 4. Close the database connection. using System using class FirstExample public static void Main try step 1 create a SqlConnection object to connect to the SQL Server Northwind database SqlConnection mySqlConnection new SqlConnection server localhost database Northwind uid sa pwd sa step 2 create a SqlCommand object SqlCommand mySqlCommand step 3 set the CommandText property of the SqlCommand object to a SQL SELECT statement that retrieves a row from the Customers table SELECT CustomerlD CompanyName ContactName Address FROM Customers WHERE CustomerlD ALFKI step 4 open the database connection using the Open method of the SqlConnection object step 5 create a SqlDataReader object and call the ExecuteReader method of the SqlCommand object to run the SELECT statement SqlDataReader mySqlDataReader step 6 read the row from the SqlDataReader object using the Read method step 7 display the column values mySqlDataReader CustomerID mySqlDataReader CustomerID mySqlDataReader

Bấm vào đây để xem trước nội dung
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
6    98    0
Đã 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.