本文介绍了使用Datatable在C#中进行批处理更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用数据表在C#中进行批处理更新?
能否请您提供一些演示示例?
在此先感谢您.
Hi,
How to do batch update in c# using data table ?
Can you please provide me some demo example ?
Thanks in Advance.
推荐答案
SqlCommand command = new SqlCommand();
// Set connection, etc.
for(int i=0; i< items.length; i++) {
command.CommandText += string.Format("update mytable set s_id=@s_id{0} where id = @id{0};", i);
command.Parameters.Add("@s_id" + i, items[i].SId);
command.Parameters.Add("@id" + i, items[i].Id);
}
command.ExecuteNonQuery();
您也可以参考以下链接
Perform Bath更新 [ ^ ].
批量更新演示 [ ^ ].
And also you can refer the following links
Performing Bath Updates[^].
Batch Update Demo[^].
var operation = new SqlBulkOperation();
// ... Custom Settings ....
operation.BulkDelete(dt);
operation.BulkInsert(dt);
operation.BulkUpdate(dt);
operation.BulkMerge(dt);
它还提供了更高级的功能,例如输出值,列公式,审核,拦截,记录等.
在 http://zzzprojects.com/bulk-operations/上找到有关最先进,最灵活的批量操作库的更多信息.
It also offers more advanced features like output value, column formula, auditing, intercepting, logging and more.
Find out more on http://zzzprojects.com/bulk-operations/ about the most advanced and flexible Bulk Operations library.
这篇关于使用Datatable在C#中进行批处理更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!