Microsoft ADO .NET 4 Step by Step - p 19

Lớp SqlCommand bao gồm một bộ sưu tập các tham số mà bạn thêm vào các giá trị thay thế cụ thể cho từng giữ chỗ. Bạn quấn lên từng tham số trong một thể hiện của SqlParameter, thiết lập thuộc tính của nó khi cần thiết, và thêm vào bộ sưu tập . | 156 Microsoft 4 Step by Step As with nonparameterized queries this enhanced statement gets wrapped up in a SqlCommand object C string sqlText @ UPDATE Employee SET Salary @NewSalary WHERE ID @EmployeeID SqlCommand salaryUpdate new SqlCommand sqlText linkToDB Visual Basic Dim sqlText As String UPDATE Employee SET Salary @NewSalary WHERE ID @EmployeeID Dim salaryUpdate New SqlCommand sqlText linkToDB The SqlCommand class includes a Parameters collection to which you add the specific replacement values for each placeholder. You wrap up each parameter in an instance of SqlParameter setting its properties as needed and adding it to the collection. When you execute the command passes both the placeholder-laden SQL text and the parameter collection to the database for evaluation. Each parameter includes the elements you would expect the parameter name which must match a placeholder name in the SQL statement the data type along with any data typespecific settings such as the length of string parameters the actual data content to be included in the processed command and a few other generic settings. To add a parameter to a command create a SqlParameter instance and add it to the SqlCommand object. C SqlParameter paramValue new SqlParameter @NewSalary 50000m paramValue paramValue new SqlParameter @EmployeeID 25L paramValue Visual Basic Dim paramValue As New SqlParameter @NewSalary 50000@ paramValue paramValue New SqlParameter @EmployeeID 25 paramValue Chapter 10 Adding Standards to Queries 157 SqlParameter includes lots of constructor options for setting the data type of the passed data plus other settings. Or you can go the traditional route and update the object s individual properties directly

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
185    470    14    09-05-2024
Đã 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.