使用 .NET 在 SYBASE 中批量插入

发布于 12-15 21:56 字数 56 浏览 4 评论 0原文

如何在 .NET 中使用 SYBASE 表中的数组进行批量数据插入。我不想使用 BCP 实用程序。

How can I do bulk data insert in Array in SYBASE table using in .NET. I don't want to use BCP utilities.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

稚气少女2024-12-22 21:56:47

有点乱
您必须使用 sp_dboption 来打开它
然后您可以使用 Select Into 来获取数据
您再次关闭该选项。
还建议您在任何长时间的操作之前删除所有触发器索引等,然后将它们放回去...

您是如何连接的,如果您使用 ODBC,您可能会很有趣,因为它往往会崩溃专有的东西,除非你通过。

发现这个,更记得以前使用delphi和sybase时遇到的类似麻烦

Sybase手册

It's a bit untidy
You have to use sp_dboption to turn it on
then you can use Select Into to get the data in
the you turn the option back off again.
It's also recomended that your drop all triggers indexes etc before and put them back after for any 'erm lengthy operation...

How are you connected up, you might have a bit of fun if you are on ODBC, as it tends to blow up on proprietry stuff, unless you put pass thru on.

Found this, fater remembering similar troubles way back when with delphi and sybase

Sybase Manual

嘴硬脾气大2024-12-22 21:56:47

您可以查看这个示例来了解如何执行插入语句。
然后,您只需要:

  1. 一次选择 Excel 的每一行
  2. 构建插入命令
  3. 执行它

(最好的方法)

  1. 构建一个包含多行的 insert into 命令(不是全部!可能每行 50 行)时间)
  2. 执行命令

附带说明,这将比做简单的事情花费更多的时间
公牛副本!

You can see this example to see how to execute the insert statement.
Then, you simply need to:

  1. select each row of the excel at a time
  2. build the insert command
  3. execute it

or (the best way)

  1. build an insert into command with several rows (not all! maybe 50 each time)
  2. execute the command

One side note, this will take a lot more time that to do the simple
bull copy!

音栖息无2024-12-22 21:56:47

经过一番调查,我发现DataAdapter能够批量插入。它有属性batchsize(我忘了名字)。我们可以指定我们要在一行中插入的行数。应指定 DataAdapter 插入命令。

After so much investigation, I found DataAdapter is able to bulk insert. It has property batchsize( I forgot the name). We can specify the number of rows, we want to insert in one trip. DataAdapter insert command should be specified.

我做我的改变2024-12-22 21:56:47

Sybase.AdoNet2.AseClient.dll 中的命名空间 Sybase.Data.AseClient 中有 AseBulkCopy 类

DataTable dt = SourceDataSet.Tables[0];

using (AseBulkCopy bulkCopy = new AseBulkCopy((AseConnection)conn))
                    {
                        bulkCopy.BatchSize = 10000;
                        bulkCopy.NotifyAfter = 5000;
                        bulkCopy.AseRowsCopied += new AseRowsCopiedEventHandler(bc_AseRowsCopied);
                        bulkCopy.DestinationTableName = DestTableName;

                        bulkCopy.ColumnMappings.Add(new AseBulkCopyColumnMapping("id", "id");

                        bulkCopy.WriteToServer(dt);
                    }


        static void bc_AseRowsCopied(object sender, AseRowsCopiedEventArgs e)
        {
            Console.WriteLine(e.RowCopied + "Copied ....");
        }

There is AseBulkCopy class in name space Sybase.Data.AseClient in Sybase.AdoNet2.AseClient.dll

DataTable dt = SourceDataSet.Tables[0];

using (AseBulkCopy bulkCopy = new AseBulkCopy((AseConnection)conn))
                    {
                        bulkCopy.BatchSize = 10000;
                        bulkCopy.NotifyAfter = 5000;
                        bulkCopy.AseRowsCopied += new AseRowsCopiedEventHandler(bc_AseRowsCopied);
                        bulkCopy.DestinationTableName = DestTableName;

                        bulkCopy.ColumnMappings.Add(new AseBulkCopyColumnMapping("id", "id");

                        bulkCopy.WriteToServer(dt);
                    }


        static void bc_AseRowsCopied(object sender, AseRowsCopiedEventArgs e)
        {
            Console.WriteLine(e.RowCopied + "Copied ....");
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文