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 / CommandObj.cs

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

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.