Re: Bulk insert ArrayList into table
- From: "news.microsoft.com" <linchi.sheaATgmailDOTcom>
- Date: Mon, 8 Jun 2009 09:28:25 -0400
I agree with Dan. SqlBulkCopy is probably perfect for you described
(especially if the data is already in memory). You cna't directly use BULK
INSERT in T-SQL with a .NET ArrayList, but it would be a breeze with
SqlBulkCopy. I've used SqlBulkCopy heavily to load generated data from
memory into SQL tables, and have found it to be quite robust.
Linchi
"Dan Guzman" <guzmanda@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:OOmlDU35JHA.1096@xxxxxxxxxxxxxxxxxxxxxxx
Another option is the SqlBulkCopy class in .NET. You can pass a data
table or a DataRow array. There is no faster way to insert data into SQL
Server than a bulk insert technique.
--
Hope this helps.
Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/
"Curious" <fir5tsight@xxxxxxxxx> wrote in message
news:7b7fa671-e6f6-461d-b2fb-ccc889305d42@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I have a C#.NET project that calls a stored procedure,
"algo_insert_swing", to insert records. Currently the stored procedure
takes a single record to insert one at a time.
CREATE PROCEDURE dbo.algo_insert_swing
(
@Cusip varchar(20),
@Ticker varchar(50),
@Type varchar(4),
@ConfirmationDate datetime,
@ExtremeDate datetime,
@ExtremePrice real,
@PercentageChange real,
@Duration int
)
AS
-- Insert a record
INSERT INTO dbo.algo_swings
(
sec_id,
ticker,
extreme_type,
confirmation,
extreme_date,
extreme_price,
percentage_change,
duration,
creation_time
)
VALUES
(
@Cusip,
@Ticker,
@Type,
@ConfirmationDate,
@ExtremeDate,
@ExtremePrice,
@PercentageChange,
@Duration,
GetDate()
)
GO
It's highly inefficient because there are so many records to insert.
I therefore, was thinking of collecting all of the records into an
ArrayList in C#.NET, and BULK INSERT the collection at once. However,
I don't know if this is possible, because I don't know if the stored
procedure can accept ArrayList as parameter and in what SQL syntax it
can INSERT the ArrayList into the table all at once.
.
- Follow-Ups:
- Re: Bulk insert ArrayList into table
- From: Curious
- Re: Bulk insert ArrayList into table
- References:
- Bulk insert ArrayList into table
- From: Curious
- Re: Bulk insert ArrayList into table
- From: Dan Guzman
- Bulk insert ArrayList into table
- Prev by Date: RE: Enabling AWE?
- Next by Date: Re: datetime month question
- Previous by thread: Re: Bulk insert ArrayList into table
- Next by thread: Re: Bulk insert ArrayList into table
- Index(es):
Relevant Pages
|