?
Solved

VB.net Speed Updating SQL table using data table

Posted on 2015-01-05
2
Medium Priority
?
179 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:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 2000 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:Murray Brown
ID: 40532938
Thanks very much
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

800 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