Excel VBA Insert multiple records using all or nothing approach

Murray Brown
Murray Brown used Ask the Experts™
on
Hi

I need to insert a few hundred records of data into a SQL database using an all or nothing (or transact rollback) approach.
What Excel VBA code would I use to do this?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
how do you insert the records? By doing multiple INSERT statements? In that case surround the block of statements by BEGIN TRAN / COMMIT TRAN.

Check https://docs.microsoft.com/en-us/sql/t-sql/language-elements/begin-transaction-transact-sql?view=sql-server-2017
Murray BrownASP.net/VSTO Developer

Author

Commented:
Thanks Eric. Do youboissibly gave an Excel VIA example? I will be looping through Excel rows and doing an SQL insert statement for each one
Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
I don't have VBA samples, I thought you already your insert statements ready!
Senior .Net Consultant
Top Expert 2016
Commented:
Murray BrownASP.net/VSTO Developer

Author

Commented:
Thanks very much Eric

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial