开发者

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

开发者 https://www.devze.com 2023-04-04 20:42 出处:网络
I know SQL Server 2000 has a bulk insert.Does it support bulk insert from a C# collection, such as a 开发者_Go百科dataset?

I know SQL Server 2000 has a bulk insert. Does it support bulk insert from a C# collection, such as a 开发者_Go百科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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号