Filip,
>In a win form I have three consecutive queries, each from a different business object.
>Prior to executing the queries I have gathered some criteria from the UI. Due to this I retrieve data using parameterized queries.
>Within each query, which is dynamic, is a base or minimum query that executes in case there are no criteria from the UI.
>As an argument to each of the queries I give a string containing all the extra criteria that is going into the query and the IDbDataParameter[] with the SqlParameters.
>
>Since each query is going to use the same criteria i thought that I could just call each query with the same criteria string and IDbDataParameter[]. But when executing the second query I receive the following System.ArgumentException from the SQLServer (I guess?) : "The SqlParameter with ParameterName '@address' is already contained by another SqlParameterCollection."
>The error occurs when the parameters of the IDbDataParameter[] is added to the DataCommand.Parameters SqlParameterCollection. What I don't get is why these parameters are still there after I have successfully received a result from the first query, from the first business object. And when is this SqlParameterCollection emptied?
It sounds like you are reusing the Data Command object for each query (some overloads of GetDataSet() accept a command object). If this is the case, you need to manually clear the Command object's Parameters collection between execution of each command. For example:
MyCommand.Parameters.Clear();
Regards,
Kevin McNeish
Eight-Time .NET MVP
VFP and iOS Author, Speaker & Trainer
Oak Leaf Enterprises, Inc.
Chief Architect, MM Framework
http://www.oakleafsd.com