将批量复制与数据表一起使用 [英] Using Bulk Copy with Data table

查看:63
本文介绍了将批量复制与数据表一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,亲爱的...
我正在使用数据适配器,并且我想通过数据库中的数据适配器更新多个记录.我该怎么做?

Hello Dear...
I am using Data Adapter, and i want to update multiple records through Data Adapter in database. How can i do that?

推荐答案

http ://msdn.microsoft.com/zh-CN/library/aadf8fk2​​.aspx [ ^ ]


用多个表填充数据集的一种方法是向数据库发送多个请求.另一种方法是在单个请求中使用多个SELECT语句.
这样做有两个问题:
DataTables与数据库中的表名称不同,您必须自行设置它们
您不能将表更新/保存到数据库;为此,必须为每个表使用单独的DataAdapter.
将myAdapter变暗为SqlDataAdapter = new SqlDataAdapter(
选择*来自客户; SELECT * FROM Orders",连接)
myAdapter.Fill(dsTables)
dsTables.Tables(0).TableName =客户")
dsTables.Tables(1).TableName =订单")
如果他们做到了,它将变得非常容易,因此您可以使用相同的DataAdapter来更新使用DataAdapter加载到DataSet中的所有表.
如果您确实尝试使用相同的DataAdapter更新所有表,则会收到类似以下的错误(此错误使我沮丧了几个小时):
system.data.dll中发生了类型为"System.InvalidOperationException"的未处理异常


谢谢与问候
Yogesh
One way to fill a DataSet with multiple tables is to send the database multiple requests. Another way to do this is to use multiple SELECT statements in a single request.
There are a couple of problems with doing it this way:
The DataTables don''t have the same name as the tables in the database, you have to set them yourself
You can''t update/save the tables to the database; to do that you must use a seperate DataAdapter for each table.
Dim myAdapter as SqlDataAdapter = new SqlDataAdapter(
"SELECT * FROM Customers; SELECT * FROM Orders", connection)
myAdapter.Fill(dsTables)
dsTables.Tables(0).TableName = "Customers")
dsTables.Tables(1).TableName = "Orders")
It would be so much easier if they made it so you can use the same DataAdapter to update all the tables you load into the DataSet with the DataAdapter.
If you do try to update all the tables with the same DataAdapter, then you will get an error like the one below (this error really frustrated me for a couple hours):
An unhandled exception of type ''System.InvalidOperationException'' occurred in system.data.dll


Thanks & Regards
Yogesh


这篇关于将批量复制与数据表一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆