我可以使用哪个vb代码将数据从dataGridView复制到sql server表中? [英] which vb code can I use to copy data from a dataGridView to pasted in a sql server table?
问题描述
我有一个表单,在那个表单中我有datagridview。我有一个按钮(浏览),它从excel表中获取数据并粘贴到datagridview中。现在我正在尝试从datagridview复制数据并粘贴到sql server表中。
I have a form and in that form I have the datagridview. I have a button (browse) which get the data from an excel table and pasted into the datagridview. Now I'm trying to copy the data from datagridview and pasted into a sql server table.
请帮助!!
推荐答案
您好,
最好的建议是将Excel加载到DataTable中DataColumn的名称与SQL-Server表中的字段名称相同,然后使用
SqlBulkCopy的。如果DataColumn名称不同,则需要在设置SqlBulkCopy类实例时映射字段。
Best advice is to load Excel into a DataTable with DataColumn names the same as the field names in the SQL-Server table then use SqlBulkCopy. If DataColumn names differ you will need to map fields when setting up the SqlBulkCopy class instance.
这篇关于我可以使用哪个vb代码将数据从dataGridView复制到sql server表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!