Solved

VB.net SQL Bulk Copy Add new rows

Posted on 2015-01-05
2
279 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: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 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:Murray Brown
ID: 40533041
Thanks
0

Featured Post

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
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: …

630 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