Create a connection object with a command
- Last UpdatedJul 22, 2024
- 1 minute read
SQLData scripts follow a typical flow when they are written without transactions:
-
Create a connection object.
-
Create one or more command objects using the CreateCommand() method of the connection object.
-
For each command object whose SQL statement contains parameters, initialize each parameter by using either the Set<Type>ParameterByName() method or the Set<Type>ParameterByIndex() method of the command object.
-
Run the command object either synchronously or asynchronously.
When command processing is complete, you can retrieve and modify the returned dataset. If you modify the dataset, you can save it back to the database either synchronously or asynchronously.
You can reuse command objects indefinitely. When finished, clean up the command objects by calling their Dispose() methods.