473,387 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

The SqlParameter with ParameterName 'xxxxx' is already contained by this SqlParameterCollection.

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 I use one parameter. If I use
multiple parameters I get the above array. Does anyone see the
problem?

I'm using APS.NET Framework 1.1, VS.NET, SQL 2000

First I put the code of the page and after that the code of the class
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

Dim objDataAccess As New
ClassLibrary1.SymaxDataAccess.clsSqlDataAccess()
Dim dummy As String
Dim dbRecordSet As SqlClient.SqlDataReader

objDataAccess.strStoredProcedure = "Select_Test"
objDataAccess.AddParameter("@Error", "", SqlDbType.Int,
ParameterDirection.Output, 4)
objDataAccess.AddParameter("@rowcount", "", SqlDbType.Int,
ParameterDirection.Output, 4)
objDataAccess.AddParameter("@FLD_Parameter", "", SqlDbType.Int,
ParameterDirection.Input, 4)
dbRecordSet = objDataAccess.DbRecordSet()
While (dbRecordSet.Read())
dummy = dummy + "<br>" + CStr(dbRecordSet(0))

End While

objDataAccess = Nothing

If Not (dbRecordSet.IsClosed) Then
dbRecordSet.Close()
End If
myLabel.Text = dummy
End Sub

Codebehind bestand Eind
Gebruikte class:
Imports System
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections

Namespace SymaxDataAccess

'************************************************* ******
'
' clsSqlDataAccess Class
'
' Business/Data Logic Class that encapsulates all data
' logic necessary to add/login/query customers within
' the [] database.
'
' TO DO: Error handeling
'************************************************* ******
Public Class clsSqlDataAccess

'************************************************* ******
' Private var's
'************************************************* ******
Private _strSP As String = ""
Private _objParamArray As New ArrayList()

Private Shared _strConnectString As String =
ConfigurationSettings.AppSettings("ConnectionStrin g")

Private Structure _ParamList
Dim ParamName As String
Dim ParamValue As Object
Dim ParamType As String
Dim ParamIO As String
Dim ParamSize As Integer
End Structure
Sub New()
MyBase.New()
_strSP = ""
End Sub
#Region "clsDataAccess Properties"
'************************************************* ******
' clsDataAccess Properties
'************************************************* ******
Public WriteOnly Property strStoredProcedure() As String
Set(ByVal Value As String)
_strSP = Value
End Set
End Property

Public ReadOnly Property DbRecordSet() As SqlDataReader
Get

' Create Instance of Connection and Command Object
Dim objConnection As New SqlConnection()
Dim objCommand As New SqlCommand()
Dim strArrayValue As _ParamList
Dim objParamValue As New SqlParameter()
With objConnection
..ConnectionString = _strConnectString
..Open()
End With

With objCommand
..CommandTimeout = 15
..CommandType = CommandType.StoredProcedure
..Connection = objConnection
..CommandText = _strSP
End With

For Each strArrayValue In _objParamArray
objCommand.CreateParameter()
objParamValue.ParameterName = strArrayValue.ParamName
objParamValue.Size = strArrayValue.ParamSize
objParamValue.Direction = strArrayValue.ParamIO
objParamValue.Precision = strArrayValue.ParamType
objCommand.Parameters.Add(objParamValue).Value =
strArrayValue.ParamValue
Next
Try

Return objCommand.ExecuteReader

Catch sqlException As Exception

objCommand.Parameters.Clear()
objCommand.Dispose()

Finally

If (objConnection.State <> ConnectionState.Closed) Then
objConnection.Close()
End If

End Try
End Get
End Property
#End Region

#Region "clsDataAccess Methods"

'************************************************* ******
' clsDataAccess Methods
'************************************************* ******

Public Sub AddParameter(ByVal ParamName, ByVal ParamValue, ByVal
ParamType, ByVal ParamIO, ByVal ParamSize)

Dim objParamList As _ParamList

objParamList.ParamName = ParamName
objParamList.ParamValue = ParamValue
objParamList.ParamType = ParamType
objParamList.ParamIO = ParamIO
objParamList.ParamSize = ParamSize

_objParamArray.Add(objParamList)

objParamList = Nothing

End Sub

#End Region

End Class

End Namespace

Error:

System.ArgumentException: The SqlParameter with ParameterName 'xxxxx'
is already contained by this SqlParameterCollection

Thx for the help
Nov 18 '05 #1
0 1734

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

Similar topics

5
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...
0
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...
2
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...
0
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:
3
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...
2
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...
2
by: DC | last post by:
The Code <%@ import namespace="System" %> <%@ import namespace="System.Web" %> <%@ import namespace="System.Web.UI" %> <%@ import namespace="System.Web.UI.HtmlControls" %> <%@ import...
0
by: DC | last post by:
The problem I'm using the .NET GridView and FormView objects for the first time and im getting the error "An OleDbParameter with ParameterName '@ID' is not contained by this...
1
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...
1
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.