SQLParameter with bulk insert.

Discussion in 'ASP .Net' started by =?Utf-8?B?UHJhZGVlcA==?=, Jul 18, 2006.

  1. 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
    =?Utf-8?B?UHJhZGVlcA==?=, Jul 18, 2006
    #1
    1. Advertising

  2. 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
    >
    =?Utf-8?B?Y2xpY2tvbg==?=, Jul 18, 2006
    #2
    1. Advertising

  3. =?Utf-8?B?UHJhZGVlcA==?=

    Hans Kesting 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


    "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
    Hans Kesting, Jul 18, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sean
    Replies:
    6
    Views:
    390
  2. =?Utf-8?B?U2hpanUgUG95aWxpbA==?=

    BULK INSERT WITH ADO.NET & ORACLE

    =?Utf-8?B?U2hpanUgUG95aWxpbA==?=, Apr 25, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    6,261
    Sathya.Pai
    Sep 9, 2009
  3. Niraj
    Replies:
    2
    Views:
    10,718
    Jim Kennedy
    Mar 3, 2004
  4. ABC
    Replies:
    1
    Views:
    721
    Galin iliev
    May 11, 2006
  5. Dave Ekhaus

    mysql bulk insert from python

    Dave Ekhaus, Oct 20, 2004, in forum: Python
    Replies:
    1
    Views:
    981
    Wolfram Kraus
    Oct 21, 2004
Loading...

Share This Page