Solved

VB.net Speed Updating SQL table using data table

Posted on 2015-01-05
2
171 Views
Last Modified: 2015-01-05
Hi

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)
                dbadp2.Fill(dTable2)
                Me.DataGridView1.DataSource = dTable2

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

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()
            dbadp2.Update(dTable2)
0
Comment
Question by:murbro
2 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 40531919
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.
0
 

Author Closing Comment

by:murbro
ID: 40532938
Thanks very much
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now