SQLParameter with bulk insert.

G

Guest

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 works fine if the loop executes for only one time, but if the loop
executes more than one time i am getting the error : "field xyz is already
contained by another SqlParameterCollection"



Function abc(Parameter_Array)

begin loop

alter Parameter_Array' values

Create command object

Add parameters to the command object //i am getting
error at this point,if this is executed for the second time .

Execute

command.parameters.close();

set connection,command etc.. to null

end
 
G

Guest

Could you post actual code rather than pseudo code, what you think you are
doing might differ subtly from what you are actually doing with the code.
 
H

Hans Kesting

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 works fine if the loop executes for only one time, but if the loop
executes more than one time i am getting the error : "field xyz is already
contained by another SqlParameterCollection"



Function abc(Parameter_Array)

begin loop

alter Parameter_Array' values

Create command object

Add parameters to the command object //i am getting
error at this point,if this is executed for the second time .

Execute

command.parameters.close();

set connection,command etc.. to null

end

"bulk insert" seems to me that the command is identical, just the
parameter values change.
I think it's more efficient (and probably solves your problem) to
rewrite like this:

create command object
create parameters with dummy values, add to command
set & open connection
begin loop
change param values
execute
end loop
close connection

Hans Kesting
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top