1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| private void InitializeCommands()
{
// Reuse the SelectCommand's Connection.
SqlConnection connection =
(SqlConnection) dataAdapter.SelectCommand.Connection;
// Create an explicit, reusable insert command
dataAdapter.InsertCommand = connection.CreateCommand();
dataAdapter.InsertCommand.CommandText =
"Insert into customers " +
"(CustomerId, CompanyName, ContactName, ContactTitle, " +
" Address, City, PostalCode, Phone) " +
"values(@CustomerId, @CompanyName, @ContactName, " +
" @ContactTitle, @Address, @City, @PostalCode, @Phone)";
AddParms(dataAdapter.InsertCommand,
"CustomerId", "CompanyName", "ContactName", "ContactTitle",
"Address", "City", "PostalCode", "Phone");
// Create an explicit update command
dataAdapter.UpdateCommand = connection.CreateCommand();
dataAdapter.UpdateCommand.CommandText = "update Customers " +
"set CompanyName = @CompanyName where CustomerID = @CustomerId";
AddParms(dataAdapter.UpdateCommand, "CompanyName", "CustomerID");
// Create an explicit delete command
dataAdapter.DeleteCommand = connection.CreateCommand();
dataAdapter.DeleteCommand.CommandText =
"delete from customers where customerID = @CustomerId";
AddParms(dataAdapter.DeleteCommand, "CustomerID");
} |
Partager