Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Different business objects with the same sql parameters
Message
De
25/07/2005 05:28:37
Filip Bruman
Kirschberg Holding
Copenhagen, Denmark
 
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Versions des environnements
Environment:
C# 1.1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01033812
Message ID:
01035621
Vues:
17
Hi Kevin,

>>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();
I am not using a version of the GetDataSet() where I pass a command object. But I could! This would give me the opportunity to clear the parameters between each query. Thanks!


Regards

-Filip
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform