Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can I "reuse" a sqlcommand object?

Status
Not open for further replies.

stucker79

Technical User
Dec 7, 2004
25
US
I would like to declare one sqlcommand object in a module that I can use across my project. Is there a way to "clear" a sqlcommand object so that I can use it again for a different stored procedure?
 
It seems to be cached or something, I change it's properties but it throws and error "too many arguments specified". if i change it to a different sqlcommand object it works fine...
 
I don't know what you mean.

Code:
Command1.CommandType = CommandType.StoredProcedure
Command1.Connection = MyConnection
Command1.CommandText = "some_sp"
Command1.Parameters.Add("@Param1", 100)

---------------------------------------

Command1.Parameters.Clear
Command1.CommandType = CommandType.Text
Command1.Connection = MyConnection
Command1.CommandText = "SELECT Something FROM Something"

should work fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top