Problem with SQLParameter

S

simon

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,282
Latest member
RoseannaBa

Latest Threads

Top