• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 186
  • Last Modified:

VB.net Speed Updating SQL table using data table


I connect to a SQL database in my VB.net project using the following code:
                dTable2 = New DataTable
                Dim connection As New SqlConnection(CS)
                dbadp2 = New SqlDataAdapter(sSQL, connection)
                Me.DataGridView1.DataSource = dTable2

I then add a few thousand rows with the following VB.net code (this is very fast)

My issue is then trying to save the new data back to SQL using the following code. It takes a few minutes.
Is there any faster way to do this?

            Dim builder As New SqlCommandBuilder(dbadp2)
            builder.QuotePrefix = "["
            builder.QuoteSuffix = "]"
            dbadp2.UpdateCommand = builder.GetUpdateCommand()
Murray Brown
Murray Brown
1 Solution
Fernando SotoRetiredCommented:
You can use SQLBulkCopy. Please read this article to learn Using SqlBulkCopy To Perform Efficient Bulk SQL Operations.

Here is the Microsoft Documentation on SqlBulkCopy Class.
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now