- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章DataAdapter执行批量更新的实例代码由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
在以前版本的 ADO.NET 中,使用 DataSet 中的更改来更新数据库时,DataAdapter 的 Update 方法每次更新数据库的一行。因为该方法循环访问指定 DataTable 中的行,所以,会检查每个 DataRow,确定是否已修改。如果该行已修改,将根据该行的 RowState 属性值调用相应的 UpdateCommand、InsertCommand 或 DeleteCommand。每一次行更新都涉及网络与数据库之间的双向数据传输。 在 ADO.NET 2.0 中,DataAdapter 公开了 UpdateBatchSize 属性。将 UpdateBatchSize 设置为正整数值将使对数据库的更新以指定大小的批次进行发送。例如,如果将 UpdateBatchSize 设置为 10,会将 10 个独立的语句组合在一起并作为一批提交。将 UpdateBatchSize 设置为 0 将导致 DataAdapter 使用服务器可以处理的最大批次的大小。如果将其设置为 1,则禁用批量更新,因为此时每次发送一行。 执行非常大的批次可能会降低性能。因此,在实现应用程序之前,应测试最佳的批次大小设置。 使用 UpdateBatchSize 属性 启用了批量更新后,DataAdapter 的 UpdateCommand、InsertCommand 和 DeleteCommand 的 UpdatedRowSource 属性值应设置为 None 或 OutputParameters。在执行批量更新时,命令的 FirstReturnedRecord 或 Both 的 UpdatedRowSource 属性值无效。 下面的过程演示如何使用 UpdateBatchSize 属性。该过程采用两个参数,一个 DataSet 对象,其中包含代表 PRoduction.ProductCategory 表中的 ProductCategoryID 和 Name 字段的列,一个代表批次大小的整数(批次中的行数)。该代码创建一个新的 SqlDataAdapter 对象,设置其 UpdateCommand、InsertCommand 和 DeleteCommand 属性。该代码假定 DataSet 对象已修改了行。它设置 UpdateBatchSize 属性并执行更新.
protected void btnUpdateAddress_Click(object sender, EventArgs e) { SqlDataAdapter EmpAdapter = new SqlDataAdapter(); DataTable EmpDT = new DataTable(); SqlConnection DBConSelect = new SqlConnection(); SqlConnection DBConUpdate = new SqlConnection(); SqlCommand SelectCommand = new SqlCommand(); SqlCommand UpdateCommand = new SqlCommand(); // Using different connection objects for select and updates from the // Northwind database. DBConSelect.ConnectionString = ConfigurationManager.ConnectionStrings["DSN_NorthWind"].ConnectionString; DBConUpdate.ConnectionString = ConfigurationManager.ConnectionStrings["DSN_NorthWind"].ConnectionString; // Reading all records from the Employees table SelectCommand.CommandText = "SELECT top 500 * FROM EMPLOYEES"; SelectCommand.CommandType = CommandType.Text; SelectCommand.Connection = DBConSelect,
。
UpdateCommand.CommandText = " UPDATE EMPLOYEES SET Address=@Address, " + "City=@City, Region=@Region, Country=@Country"; UpdateCommand.CommandType = CommandType.Text; UpdateCommand.Connection = DBConUpdate; SqlParameter AddressParam; AddressParam = new SqlParameter("@Address", SqlDbType.VarChar, 15, "Address"); SqlParameter CityParam; CityParam = new SqlParameter("@City", SqlDbType.VarChar, 15, "City"); SqlParameter RegionParam; RegionParam = new SqlParameter("@Region", SqlDbType.VarChar, 15, "Region"); SqlParameter CountryParam; CountryParam = new SqlParameter("@Country", SqlDbType.VarChar, 15, "Country"); UpdateCommand.Parameters.Add(AddressParam); UpdateCommand.Parameters.Add(CityParam); UpdateCommand.Parameters.Add(RegionParam); UpdateCommand.Parameters.Add(CountryParam); // Setting up Data Adapter with the Select and Update Commands // The Select command will be used to retrieve all employee // information from the Northwind database and the Update command // will be used to save changes back to the database EmpAdapter.SelectCommand = SelectCommand; EmpAdapter.UpdateCommand = UpdateCommand; EmpAdapter.Fill(EmpDT); DBConSelect.Close(); // Looping through all employee records and assigning them the new // address foreach (DataRow DR in EmpDT.Rows) { DR["Address"] = "4445 W 77th Street, Suite 140"; DR["City"] = "Edina"; DR["Region"] = "Minnesota"; DR["Country"] = "USA"; } // Adding an event handler to listen to the RowUpdated event. // This event will will fire after each batch is executed EmpAdapter.RowUpdated += new SqlRowUpdatedEventHandler(OnRowUpdated); lblCounter.Text = ""; EmpAdapter.UpdateBatchSize = 100; // It is important to set this property for batch processing of // updated records since batch updates are incapable of // updating the source with changes from the database UpdateCommand.UpdatedRowSource = UpdateRowSource.None; try { DBConUpdate.Open(); EmpAdapter.Update(EmpDT); } catch (Exception ex) { lblCounter.Text += ex.Message + "<Br>"; } finally { if (DBConUpdate.State == ConnectionState.Open) { DBConUpdate.Close(); } } } private void OnRowUpdated(object sender, SqlRowUpdatedEventArgs args) { lblCounter.Text += "Batch is processed till row number = " + args.RowCount.ToString() + "<br>"; } 。
。
最后此篇关于DataAdapter执行批量更新的实例代码的文章就讲到这里了,如果你想了解更多关于DataAdapter执行批量更新的实例代码的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我有一个“有趣”的问题,即以两种不同的方式运行 wine 会导致: $> wine --version /Applications/Wine.app/Contents/Resources/bin/wi
我制作了这个网络抓取工具来获取网页中的表格。我使用 puppeteer (不知道 crontab 有问题)、Python 进行清理并处理数据库的输出 但令我惊讶的是,当我执行它时 */50 * * *
JavaScript 是否被调用或执行取决于什么?准确地说,我有两个函数,它们都以相同的方式调用: [self.mapView stringByEvaluatingJavaScriptFromStri
我目前正在使用 python 做一个机器学习项目(这里是初学者,从头开始学习一切)。 只是想知道 statsmodels 的 OLS 和 scikit 的 PooledOlS 使用我拥有的相同面板数据
在使用集成对象模型 (IOM) 后,我可以执行 SAS 代码并将 SAS 数据集读入 .Net/C# 数据集 here . 只是好奇,使用 .Net 作为 SAS 服务器的客户端与使用 Enterpr
有一些直接的 jQuery 在单击时隐藏打开的 div 未显示,但仍将高度添加到导航中以使其看起来好像要掉下来了。 这个脚本工作正常: $(document).ready(funct
这个问题已经有答案了: How do I compare strings in Java? (23 个回答) 已关闭 4 年前。 这里是 Java 新手,我正在使用 NetBeans 尝试一些简单的代
如果我将它切换到 Python 2.x,它执行 10。这是为什么? 训练逻辑回归模型 import keras.backend as
我有两个脚本,它们包含在 HTML 正文中。在第一个脚本中,我初始化一个 JS 对象,该对象在第二个脚本标记中引用。 ... obj.a = 1000; obj.
每当我运行该方法时,我都会收到一个带有数字的错误 以下是我的代码。 public String getAccount() { String s = "Listing the accounts";
我已经用 do~while(true) 创建了我的菜单;但是每次用户输入一个数字时,它不会运行程序,而是再次显示菜单!你怎么看? //我的主要方法 public static void main(St
执行命令后,如何让IPython通知我?我可以使用铃声/警报还是通过弹出窗口获取它?我正在OS X 10.8.5的iTerm上运行Anaconda。 最佳答案 使用最新版本的iTerm,您可以在she
您好,我刚刚使用菜单栏为 Swing 编写了代码。但是问题出现在运行中。我输入: javac Menu.java java Menu 它没有给出任何错误,但 GUI 没有显示。这是我的源代码以供引用:
我觉得这里缺少明显的东西,但是我看不到它写在任何地方。 我使用Authenticode证书对可执行文件进行签名,但是当我开始学习有关它的更多信息时,我对原样的值(value)提出了质疑。 签名的exe
我正在设计一个应用程序,它使用 DataTables 中的预定义库来创建数据表。我想对数据表执行删除操作,为此应在按钮单击事件上执行 java 脚本。 $(document).ready(functi
我是 Haskell 新手,如果有人愿意帮助我,我会很高兴!我试图让这个程序与 do while 循环一起工作。 第二个 getLine 命令的结果被放入变量 goGlenn 中,如果 goGlenn
我有一个用 swing 实现迷你游戏的程序,在主类中我有一个循环,用于监听游戏 map 中的 boolean 值。使用 while 实现的循环不会执行一条指令,如果它是唯一的一条指令,我不知道为什么。
我正在尝试开发一个连接到 Oracle 数据库并执行函数的 Java 应用程序。如果我在 Eclipse 中运行该应用程序,它可以工作,但是当我尝试在 Windows 命令提示符中运行 .jar 时,
我正在阅读有关 Java 中的 Future 和 javascript 中的 Promises 的内容。下面是我作为示例编写的代码。我的问题是分配给 future 的任务什么时候开始执行? 当如下行创
我有一个常见的情况,您有两个变量(xSpeed 和 ySpeed),当它们低于 minSpeed 时,我想将它们独立设置为零,并在它们都为零时退出。 最有效的方法是什么?目前我有两种方法(方法2更干净
我是一名优秀的程序员,十分优秀!