Solved

Append to a SQL table from an array

Posted on 2013-11-20
5
284 Views
Last Modified: 2013-11-20
Is there a way to INSERT INTO a table from an array?

I do not have permissions for a BULK INSERT.

The array has 2 columns.

Col1 needs to be inserted into Col1 of the table.

Col2 needs to be inserted into Col2 of the table.

Can the array can be passed as a parameter into the stored procedure?

-- @arrExceptions  This is the 2 column array

      @SymbolID int,   -- From col1,row i of the array
      @Curr5DayAvg float, -- From col2,row i of the array


INSERT INTO Exceptions FROM the array.

(SymbolID, Curr5DayAvg)

VALUES (@SymbolID,@Curr5DayAvg)
0
Comment
Question by:Dovberman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 25

Expert Comment

by:SStory
ID: 39662675
I am not aware of the array being able to be passe from VB/VC# to the stored proc. However it is easy enough to write a
SQLCommand object with parameters such that you can loop

for (int i=0;i<whatever to of array is;i++) {
        'stuff ArrayName[i,0] into  into SQL command parameter variable
        'repead with ArrayName[i,1] into the second
         'Execute the SQL Command

         'repeat process
}

Here's an example:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar%28v=vs.110%29.aspx
0
 

Author Comment

by:Dovberman
ID: 39662935
I am doing something like this now.

The array has 1500 rows. It requires the sql statement to be executed 1500 times.

This times out the server.

Does the proposed method require the sql statement to be executed 1500 times?

 'Execute the SQL Command

         'repeat process
0
 
LVL 2

Accepted Solution

by:
Subhasree earned 500 total points
ID: 39663341
An array cannot be passed as an arguement to a stored procedure.

If executing the sql command 1500 times is not practical for you,
You can write this in to xml file. Later execute a stored proced which reads the xml and insert the rows to the table without using BULK INSERT.
0
 

Author Comment

by:Dovberman
ID: 39663519
Thanks.  I will write the rows to an xml file.
0
 

Author Closing Comment

by:Dovberman
ID: 39663524
Thanks,

I will use the xml file approach.
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question