473,699 Members | 2,532 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trouble Removing SqlParameter objects from Command object

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 my Command object.

The problem comes up when I try to append a SqlParameter object that I have
already used in a previous call, that is also an argument for the next
stored procedure. For example, I have:

dim objParam1 as New SqlParameter("@ userid", intUserid)
dim objDS as DataSet
objDS = objDAL.GetDataS et("storedprocn ame", objParam1)

' do some stuff with the dataset, now try a new query, different proc, same
parameter
objDS.clear()
objDS = objDAL.GetDataS et("anotherproc name", objParam1)

The error returned is something like "There is already a parameter named
objParam1 in the SqlParametersCo llcetion.

Prior to adding each parameter, I check its count and, if greater than 0,
remove each item before appending the new params. In debugging the count is
always 0, so how can there be an SqlParameter object in its collection?

' create our command object with the passed in ProcedureName.

' and sqlparameter object.

Dim objCommand As New SqlCommand(Proc edureName, Me.Connection)

Dim sqlParam As SqlParameter

objCommand.Comm andType = CommandType.Sto redProcedure

Me.LocalCommand = objCommand

If objCommand.Para meters.Count > 0 Then

' in case any parameters are hanging around, clear them out

For Each sqlParam In objCommand.Para meters

objCommand.Para meters.Remove(s qlParam)

Next

End If

objCommand.Para meters.Clear()

' add the parameters passed in from the ParamArray

' into the command's parameters collection.

For Each sqlParam In DataParameters

sqlParam = objCommand.Para meters.Add(sqlP aram) ' ERROR THROWN HERE

Next

What element am I missing please? This has me bending my brain pretty badly.
Thank you in advance.
Nov 20 '05 #1
0 2752

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

Similar topics

5
8298
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?
0
2227
by: kevin | last post by:
....using VS2003 and the Enterprise Library whenever I want to use an SP I query the database for the parameters (INFORMATION_SCHEMA.PARAMETERS) and then populate the command objects parameters collection like thus (params is an array of SqlParameters) foreach(SqlParameter p in params){ dbcmd.Command.Parameters.Add(p); } ....//do something
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...
6
3795
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory” exception. To get an idea what happens I traced some values using performance monitor and got the following values (for one day): \\FFDS24\ASP.NET Applications(_LM_W3SVC_1_Root_ATV2004)\Errors During Execution: 7 \\FFDS24\ASP.NET Apps v1.1.4322(_LM_W3SVC_1_Root_ATV2004)\Compilations
3
1310
by: Nathan Sokalski | last post by:
I am having trouble removing cookies that I created with my site. Here is the code I am using to try and remove them: If Not Request.Cookies("username") Is Nothing Then Response.Cookies.Remove("username") If Not Request.Cookies("password") Is Nothing Then Response.Cookies.Remove("password")
5
1435
by: mlg1906 | last post by:
I'm developing an intranet site in ASP.NET 2.0 but I can't seem to connect to the DB from within my code. I've created a .vb class that houses a private Connection() that other functions within the class can call to connect to the database. In the calling function, I've declared my connection object and called the "Open" method on the object. However, when I attempt to execute the stored procedure command by calling the "ExecuteScalar"...
1
2414
by: BobRoyAce | last post by:
I have a class that has several Subs that do DB things, some of which require the same set of parameters to be passed to a stored procedure. One class has 12 parameters and part of code used to create them is shown below: Dim SQLParam(12) As SqlClient.SqlParameter SQLParam(0) = New System.Data.SqlClient.SqlParameter With SQLParam(0) .ParameterName = "@pkUserIDOriginal"
10
1548
by: daschicken | last post by:
Hi guys, ive written the following method. its supposed to delete objects in a LinkedList. These objects implicit Connections to other objects. if one object is deleted all the connections in the other objects should be deleted as well. all in all this code should do what I want. the only problem is that i get an ConcurrentModificationException running it. in the API it says
5
13364
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL http://mghospedagem.com/images/controlpanel.jpg instead of http://mghospedagem.comhttp://mghospedagem.com/images/controlpanel.jpg As u see, there's the website URL before the image URL.
0
8705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8628
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8943
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,...
1
6550
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
5884
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
4391
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...
0
4637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3075
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
2
2362
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.