Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Different business objects with the same sql parameters
Message
 
À
19/07/2005 09:24:12
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:
01035310
Vues:
14
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform