将数据从Gridview插入到DB [英] Insert Data from Gridview to DB

查看:65
本文介绍了将数据从Gridview插入到DB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,



我有疑问。请指导我。



我在Gridview中有很少的记录,我希望它能插入到数据库中。

现在天气我可以直接从Gridview插入或者我转换为XML格式然后我可以插入数据库。

哪种方法是正确的?



Gridview有这些文章有用:

MSDN:ASP.NET 2.0的GridView示例:编辑GridView中的基础数据 [ ^ ]

选择,更新和删除ASP.NET GridView控件中的数据。 [< a href =http://www.c-sharpcorner.com/uploadfile/anjudidi/select-update-and-delete-data-in-a-Asp-Net-gridview-control/target =_ bl anktitle =新窗口> ^ ]



试用。如果您遇到任何问题,请发布具体问题。


1。如果您只有200行,并且将来增加行数的可能性较小,那么您可以遍历数据网格视图并一次在字符串变量中生成INSERT语句,并使用sqlCommand对象执行语句。 />


2.如果需要插入大量数据,我更喜欢使用网格视图的数据准备DataTable,并使用SqlBulkCopy将行加载到数据库。

Dear Friends,

I have doubt. Kindly guide me on this.

I have few records in Gridview and I want it to insert to DB.
Now weather I can directly insert from Gridview or Shall I convert to XML format and then I can insert to DB.
Which way is correct?

The Gridview has more than 200 rows.

解决方案

Are these articles helpful:
MSDN: GridView Examples for ASP.NET 2.0: Editing the Underlying Data in a GridView[^]
Select, Update, and Delete Data in a ASP.NET GridView Control.[^]

Try out. Post specific issue if you face any.


1. If you have only 200 rows and there is less possibility to increase the number of rows in future then you can loop through the data-grid view and make INSERT statements in a string variable at a time and execute the statements using sqlCommand object.

2. If you need to insert large volume of data then I prefer to prepare a DataTable using the data of the grid-view and use SqlBulkCopy to load the rows to database.


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

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