TAILIEUCHUNG - Supplying Parameters to Commands

Supplying Parameters to Commands In the examples you've seen up to this point, the values for each column have been hardcoded in the SQL statements. | Supplying Parameters to Commands In the examples you ve seen up to this point the values for each column have been hardcoded in the SQL statements. For example in Listing shown earlier the INSERT statement that added the row to the Customers table was INSERT INTO Customers CustomerlD CompanyName VALUES J3COM Jason Price Corporation As you can see the values for the CustomerID and CompanyName columns are hardcoded to J3COM and Jason Price Corporation . If you had to execute many such INSERT statements hard-coding column values would be tiresome and inefficient. Fortunately you can use parameters to solve this problem. Parameters allow you specify different column values when running your program. To execute a command containing parameters you use the following high-level steps 1. Create a Command object containing a SQL statement with parameter placeholders. These placeholders mark the position where a parameter will be supplied. 2. Add parameters to the Command object. 3. Set the parameters to specified values. 4. Execute the command. Let s take a look at the details of the four steps when using parameters with SQL Server. Step 1 Create a Command Object Containing a SQL Statement with Parameter Placeholders This is straightforward wherever you would normally place a column value in your SQL statement you specify a parameter placeholder instead. A placeholder marks the position where a value will be supplied later. The syntax you use for the placeholders depends on the database you are using. With SQL Server example placeholders would be @CustomerID and @CompanyName. The following INSERT statement uses these placeholders for the CustomerID CompanyName and ContactName column values of the Customers table INSERT INTO Customers CustomerlD CompanyName ContactName VALUES @CustomerID @CompanyName @ContactName You can use a placeholder anywhere a column value is valid in a SELECT INSERT UPDATE or DELETE statement. Here are some examples of SELECT UPDATE and DELETE .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.