Reusing the Command Object

It does happen a lot that we have to perform multiple database operations as a part of a transaction or fire multiple queries. We would definitely like the code to be as efficient as possible. One way

ITPro Today

May 25, 2004

1 Min Read
ITPro Today logo in a gray background | ITPro Today

It does happen a lot that we have to perform multiple database operations as a part of a transaction or fire multiple queries. We would definitely like the code to be as efficient as possible. One way to improve efficiency is to reuse the command object, in effect having just one command object which is used for all database operations

Let's see how can we reuse the same Command object to perform multiple queries on the database. You can view the code below. I have created a console-based application to demonstrate the Command object reuse. There is no exception handling in the code for better code understanding.

You can compile the above code using the following command at the command prompt.

csc /r:System.data.dll CommandObj.cs

You can run the CommandObj.exe at the command prompt. Happy Coding !!!

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like