views:

154

answers:

2

Hi guys,

In order to do my stuff, I query the database (Access) to see if my data is already there. So, I'm using a OleDbDataReader. Everything is fine at this moment.

Next, depending on the result of my query, I'm doing an insert or and update. The problem is, this operation is using the same parameters (OleDbParameters) that I was using for my first query.

So when I'm trying to add these parameters to the command, I'm getting this error :

The OleDbParameter is already contained by another OleDbParameterCollection

I tried everything to clear those parameters : - Close on the OleDbDataReader - Dispose on the OleDbDataReader - myOleDbDataReader = null

But nothing seems to work.

Anyone has any idea ?

Thanks a lot.

+2  A: 

To disassociate the OleDbParameters from the OleDbParameterCollection you could use the Remove Method on the OleDbParameterCollection. As an alternative, the Clear Method would perform this action for all of the parameters in the collection in one step.

You should also be careful about using a single connection with multiple commands. You'll find more information on this topic here.

Scott Munro
Thank you, it was the right answer !
esylvestre
A: 

can you post some code to see if i can help

peacmaker