473,396 Members | 1,847 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,396 software developers and data experts.

Problem with SQLParameter

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:

createAdapter("c_storedProcedure1", False, myParams).Fill(ds, "table1")

When I create second adapter, i get an error message:

createAdapter("c_storedProcedure2", False, myParams).Fill(ds, "table2")

"The SqlParameter with ParameterName 'XXXX' is already
contained by another SqlParameterCollection."

And the function wich create dataAdapter is:
Function createAdapter(ByVal sqlStr As String, Optional ByVal type As Boolean = True, Optional ByVal myParams As Collection = Nothing) As SqlDataAdapter

Dim mySqlAd As SqlDataAdapter
Dim i As Int16

mySqlAd = New SqlDataAdapter(sqlStr, createConnection)

mySqlAd.SelectCommand.Parameters.Clear()

If type = False Then 'stored procedure
mySqlAd.SelectCommand.CommandType = CommandType.StoredProcedure
If Not myParams Is Nothing Then

Dim param As SqlParameter
For Each param In myParams

mySqlAd.SelectCommand.Parameters.Add(param)
param = Nothing
Next
End If
End If

createAdapter = mySqlAd

End Function

I add here Clear method but no help.

Any suggestion?

Thank you,

Simon

Nov 19 '05 #1
0 1114

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

Similar topics

3
by: Simon Harvey | last post by:
Hi everyone, I'm having a very frustrating problem executing a stored procedure. I'll put the code at the bottom. When I build the SP and add all the parameters everything goes as expected....
2
by: Gaab | last post by:
Hi Folks, I've created a stored procedure (Incident_Add) and called it, but when I excecute it in the code it says: "System.Data.SqlClient.SqlException: Line 1: incorrect syntax at...
5
by: Lasse Edsvik | last post by:
Hello I have this: public SqlParameter GetParameter(string sqlparam) { SqlParameter param = cmd.Parameters.Add(sqlparam);
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...
3
by: Bilbo | last post by:
I have a a headscratcher here: I have a form that when submitted should do 2 things when a user enters data and then clicks the Add button. Here goes: 1. Call a stored procedure called...
4
by: Bass Pro | last post by:
Hi, I am creating textbox, radiobuttonlist and checkboxlist dynamically depending on data from a table. It is a questionnaire. I add the control on a Panel control during the 1st load_page event....
3
by: c676228 | last post by:
Hi all, I think I have data type problem when I tried to insert data into sql server 200. The erroe message is like this: system.invalidcastexception data type DFlage char(1) in sql 2000, DMI...
2
by: Krishna | last post by:
Hi, I have developed a for dataentry by using datagird in C# windows application, I am using combocolumns, textbox columns for the same, two readonly textboxcolumns for those readonly columns i...
2
by: Constantine | last post by:
Hi, I have developed one class called CProductInfo providing == and != operator features. I have one problem. When I use this class in my program, say CProductInfo product = null; and...
3
by: Constantine | last post by:
Hi, I have developed one class called CProductInfo providing == and != operator features. I have one problem. When I use this class in my program, say CProductInfo product = null; and...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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...
0
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,...

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.