我如何将Gridview的多个记录批量插入数据库 [英] How can i insert multiple records of Gridview to database in Batch

查看:85
本文介绍了我如何将Gridview的多个记录批量插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有gridview包含10条记录和一个按钮名称保存,当我单击保存"按钮时,所有5条记录必须一次保存在数据库中,这表示批处理模式.


请给我一个解决方案.



i have gridview contains 10 records and one button name save when i click on save button all five records must be save in database at a time means batch mode.


please give me a solution.

推荐答案

您可以遍历网格视图重新编码并在循环内调用insert quarry.

您可以像这样使用foreach循环
you can loop through grid view recodes and call insert quarry inside the loop.

you can use foreach loop like this
foreach (DataGridViewRow row  in dataGridView1.Rows)
{
    //do your insert inside this block.
}


一种有效的批量插入方法是从datagrid准备xml,然后将xml传递给存储过程.将xml中的数据提取到存储过程中,然后将数据从存储过程本身插入数据库中.


希望有帮助!
An efficient way to do batch insert is prepare xml from datagrid and then pass xml to stored procedure. Extract data from xml into stored procedure and insert data to database from stored procedure itself.


Hope this help!


这篇关于我如何将Gridview的多个记录批量插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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