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

SQLParameter with bulk insert.

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

Jul 18 '06 #1
2 1795
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.
"Pradeep" wrote:
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
Jul 18 '06 #2
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
Jul 18 '06 #3

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

Similar topics

2
by: php newbie | last post by:
Hello, I am trying to load a simple tab-delimited data file to SQL Server. I created a format file to go with it, since the data file differs from the destination table in number of columns. ...
5
by: me | last post by:
I'm also having problems getting the bulk insert to work. I don't know anything about it except what I've gleened from BOL but I'm not seeming to get anywhere...Hopefully there is some little (or...
7
by: iqbal | last post by:
Hi all, We have an application through which we are bulk inserting rows into a view. The definition of the view is such that it selects columns from a table on a remote server. I have added the...
5
by: Kenneth | last post by:
Can anyone explain me why it is neccesary to include SqlDbType to the SqlParameter. In every example I see, it is done, but no one explaines why. I have for example a date I want to save into my...
6
by: pk | last post by:
Sorry for the piece-by-piece nature of this post, I moved it from a dormant group to this one and it was 3 separate posts in the other group. Anyway... I'm trying to bulk insert a text file of...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
3
by: moonriver | last post by:
Right now I develop an application to retrieve over 30,000 records from a binary file and then load them into a SQL Server DB. So far I load those records one by one, but the performance is very...
0
by: ozkhillscovington | last post by:
We have sp's in place that do BULK INSERTS from txt files into the tables. This works fine, however they have asked us to add a field that identifies accounting ctr. The only thing that identifies...
0
by: rshivaraman | last post by:
BULK INSERT bill_tbl FROM 'd:\ftp_Data\in\baddress.dat' WITH ( FIELDTERMINATOR = ';', ROWTERMINATOR = '\n' ) --------------------------------- This is the query used to populate bill_tbl....
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: 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...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
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
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.