Thực hiện cập nhật hàng loạt với ADO và SQL Server Sự khác biệt lớn nhất giữa phần này và một trong những trang trước là một thực tế là trong phần cuối, một recordset đang được dân cư sử dụng một đối tượng Command. | Executing Batch Updates with ADO and SQL Server The biggest difference between this section and the previous one is the fact that in the last section a recordset being populated using a Command object. With the Command object no data was affected. That is one type of use for a Command object. What if you want to perform bulk tasks against a recordset This is the major use for using the Command object because you don t necessarily need it for populating a recordset. The Parameter object is also not used. It was not necessary for the example although you would want to use it if criteria were being implemented. To learn how to perform a bulk operation using ADO in Visual Basic .NET see this simple Update SQL statement shown here Update Orders Set ShippedDate DeliveryDate 1 This statement adds a day to the date in the ShippedDate column for all the records in the Orders table. This statement is being assigned to the CommandText property of the Command object instead of to the name of a stored procedure. Another important task is setting the CommandType property to be . This tells ADO that you are performing a bulk operation. Last the Execute method is called from the Command object. This routine called ExecuteABatchCommand can be seen in Listing . Listing Creating and Executing a Bulk Query Sub ExecuteABatchCommand ByVal txtResults As TextBox Dim cnn As New Dim cmd As New Dim prm As Dim rstOld As New Dim rstNew As New -- In .NET we can assign values as we declare variables Dim strSQL As String Update Orders Set ShippedDate ShippedDate 1 Dim strDispSQL As String _ Select OrderID ShippedDate From Orders Where OrderID 10251 -- Open the connection OpenNorthwindADOConnection cnn -- Open the Orders table and display the ShippedDate as they were. strDispSQL cnn Old Values vbCrLf vbCrLf -- Set up