Solved

VB.net SQL Bulk Copy Add new rows

Posted on 2015-01-05
2
276 Views
Last Modified: 2015-01-06
Hi
The following code in my project uses the bulk copy class to upload a new data table created in Excel called "dtExcelData". I now have a different situation where I connect to a SQL database table using a data table
and add new rows to this data table. How do I alter the code below to commit these changes to a data table?


                    Using sqlBulkCopy As New SqlBulkCopy(con)

                        'Set the database table name
                        sqlBulkCopy.DestinationTableName = oTableName
                        sqlBulkCopy.BulkCopyTimeout = 0 'Indefinite when zero

                        For k As Integer = 0 To UBound(arrSplitColumns)
                            oColumn = arrSplitColumns(k)
                            sqlBulkCopy.ColumnMappings.Add(oColumn, oColumn)
                        Next


                        con.Open()

                        sqlBulkCopy.WriteToServer(dtExcelData)

                        con.Close()

                    End Using

                End Using

            End Using
0
Comment
Question by:murbro
[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 39

Accepted Solution

by:
Pratima Pharande earned 500 total points
ID: 40533036
sqlBulkCopy.WriteToServer(dtExcelData)

will save data toserver
but you can do dedicated bulk copy operation intransaction if you want

check this link for more details

http://msdn.microsoft.com/en-us/library/tchktcdk(v=vs.110).aspx
0
 

Author Closing Comment

by:murbro
ID: 40533041
Thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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 …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

738 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