简体   繁体   中英

SQL Server 2000 - Bulk insert from dataset/or C# collection

I know SQL Server 2000 has a bulk insert. Does it support bulk insert from a C# collection, such as a dataset?

I need to insert 30 rows at a time, fairly regularly. I don't want to create 30 DB connections for this if I don't have to.

Have a look at SqlBulkCopy (has according to forums SQL 2000 support). It's easy to use. Basically just provide it with a data table (or data reader) and it will copy the rows from that source to your destination table.

You can insert using a DataSet in SQL 2000, I've never tried because I never use DataSets.

http://www.dotnet247.com/247reference/msgs/3/16570.aspx has a good post on it:

(From the article)

Steps involved 1.Create SqlDataAdapter with proper select statement

2.Create dataset and fill dataset with SqlDataAdapter

3.Add rows to the table in the dataset (for all the actions you said above, like radio button selected, check box enabled)

4.Use SqlCommandBuilder helper object to generate the UpdateStatements. Its very easy to use command builder. Just a one call to the SqlCommandBuilder constructor.

5.Once your are done adding rows to the datatable int the dataset call SqlDataAdapter.update and pass the modified dataset as a parameter. This should automatically add the rows from dataset to the database.(if no database error occurs)

Have you considered XML?

Working with XML in SQL 2000 isn't as nice as in 2008, but it is still doable:

http://www.codeproject.com/KB/database/insxmldatasqlsvr.aspx

http://www.codeproject.com/KB/database/generic_OpenXml.aspx

http://support.microsoft.com/default.aspx?scid=kb;en-us;315968

Another option you could look at would be to:

Open Connection.
Iterate through the inserts

Close Connection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM