473,749 Members | 2,626 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SqlParameter X is already contained by another SqlParameterCol lect

....using VS2003 and the Enterprise Library

whenever I want to use an SP I query the database for the parameters
(INFORMATION_SC HEMA.PARAMETERS ) and then populate the command objects
parameters collection like thus (params is an array of SqlParameters)

foreach(SqlPara meter p in params){
dbcmd.Command.P arameters.Add(p );
}
....//do something
dbcmd.SetParame ter("@pending_i d",iCredId);
....//dosomething
dbcmd.Command.P arameters.Clear ();
dbcmd.Dispose() ;
dbcmd = null;

In some cased the above is wrapped in a for() loop and other times the
method is simply called a second time.

The first step through is fine, but then subsequent runs generates the error
in the subject, so I did this...

foreach(SqlPara meter p in params){
if(!dbcmd.Comma nd.Parameters.C ontains(p.Param eterName)){
dbcmd.Command.P arameters.Add(p );}
}
....//do something
dbcmd.SetParame ter("@pending_i d",iCredId); //Enterprise Library
DBCommandWrappe r method
....//dosomething
dbcmd.Command.P arameters.Clear ();
dbcmd.Dispose() ;
dbcmd = null;

this generated an error at the SetParameter() line that indicated that
"@pending_i d" was not part of the parameter collection

So I got real smart and tried this....

foreach(SqlPara meter p in params){
try{
dbcmd.Command.P arameters.Add(p );}
catch{}
}
....//do something
dbcmd.SetParame ter("@pending_i d",iCredId);
....//dosomething
dbcmd.Command.P arameters.Clear ();
dbcmd.Dispose() ;
dbcmd = null;

....but I get the same message that @pending_id is not part of the parameter
collection.

Waiting patiently for help...
Nov 17 '05 #1
0 2229

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
8300
by: Jason Huang | last post by:
Hi, The SqlParameter myPM =new SqlParameter("@Address", txtAddress.Text) is working for update, but SqlParameter myPM =new SqlParameter ("@Address",SqlDbType.NVarChar,90,txtAddress.Text) is not working. The Address column is DataType NVarChar 90, no problem. Any idea?
2
301
by: Stephan | last post by:
Hi, I'm experiencing the problem mentioned in the title above. Briefly, I build a page in which I include a class. This class contains a procedure to add a value to an ArrayList. The value is hold by a structure. So all elements in the arraylist are in fact a structure. As you can see in the code below. Now what I'm trying to do is for each value in the Arraylist create and add a parameter. Then I try to execute a SP. This only works if...
0
1130
by: simon | last post by:
I have collection: Dim myParams As New Collection Then I fill it with parameters. Now, I would like to use it more than 1 time. When I create first dataAdapter, it works:
0
2755
by: Elliot M. Rodriguez | last post by:
I implemented a very small, basic data access layer for my web application. It works just fine, except for this one bug. One of my methods returns an abstracted dataset. To accomodate X number of input parameters, I created a function signature that accepts a ParamArray of SqlParameters as well as the name of the stored proc. In the body of the function I loop through the param array and append each object to the Parameters collection of...
3
2764
by: Stacey Levine | last post by:
I have a webservice that has the below procedure. Basically a procedure to called a stored procedure and return the results. When I try to call the webservice from my program I get the error. Both my calling code and the webservice code are below. Thanks for your help. D:\Projects .NET\StoreBO\frmVoids.vb(182): Value of type '1-dimensional array of System.Data.SqlClient.SqlParameter' cannot be converted to '1-dimensional array of...
2
1810
by: Pradeep | last post by:
I am having a function which accepts Database parameter array, and it inserts to the database inside a loop. Note: inside the loop i am changing the values of the parameter array . it works fine if the loop executes for only one time, but if the loop executes more than one time i am getting the error : "field xyz is already contained by another SqlParameterCollection"
6
7843
by: Tim Zych | last post by:
' Declare a new parameter object Dim param() As SqlParameter = New SqlParameter(0) {} ' Set this to null and make it an InputOutput parameter param(0) = New SqlParameter("@Something, DBNull.Value) ' Can also be non-null, but sometimes is null param(0).Direction = ParameterDirection.InputOutput ' But, before we begin, store a copy of the existing parameters into another variable Dim param2() As SqlParameter = New SqlParameter(0) {}...
1
2128
by: tsorgi | last post by:
I'm writing a data conversion application to support a system migration. The code is reading formatted text files and loading them into MS SQL 2005 database tables. I wanted to call the existing INSERT stored procedures in the database to perform the update, yet I don't want to hard-code all the parameter names. Below is a bit of code that reads the imported data from the 'Data' DataTable, and prepares to insert it into the database table...
1
5009
by: Dhananjay | last post by:
Hi all I have got this error An SqlParameter with ParameterName '@employment' is not contained by this SqlParameterCollection in asp.net
0
9389
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9256
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8257
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6801
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6079
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4709
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3320
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2218
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.