none
which vb code can I use to copy data from a dataGridView to pasted in a sql server table? RRS feed

  • Question

  • 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.

    Please help!!


    Wednesday, March 28, 2018 7:52 PM

All replies

  • Hello,

    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.

    Or from Excel to SQL-Server.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Wednesday, March 28, 2018 8:19 PM
    Moderator
  • Hi Moralep,

    You want to import excel data into sql server, you don't need to using datagridview, here is the example about this, you can take a look:

    https://code.msdn.microsoft.com/office/Import-Excel-Spreadsheet-2b7ca7cf

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, March 29, 2018 2:32 AM
    Moderator