|
-
Aug 26th, 2005, 01:30 PM
#1
Thread Starter
PowerPoster
INSERT versus ADDNEW [RESOLVED]
Which do you find the most efficient? Does it make a difference?
INSERT INTO tablename ([fieldnames]) values (...)"
or
Set rs as adodb.record
rs.open...
rs.addnew
...
...
..
rs.update
rs.close
set rs = nothing
Last edited by Pasvorto; Aug 26th, 2005 at 03:03 PM.
-
Aug 26th, 2005, 01:38 PM
#2
Re: INSERT versus ADDNEW
I can't attest to speed as it isn't something that I've every bothered to check, but I do not like using data controls, so I always use SQL.
-
Aug 26th, 2005, 02:11 PM
#3
Re: INSERT versus ADDNEW
My experience has been that 1000 .AddNews followed by .Update (or even .BatchUpdate) is slower than the same 1000 inserts using an SP and Insert Into.
I think it has to do with shuttling the entire data set across to the DB (even the unchanged tables) rather than just the simple command to insert the data. Generaly, if I can help it, I *always* use SPs and SQL rather than recordsets to manipulate my data. But I could just be weird like that.
Tg
-
Aug 26th, 2005, 02:24 PM
#4
Re: INSERT versus ADDNEW
Insert Into every time...
Even more efficient if your value source can be loaded into a table beforehand (Imported data) rather than numerous values statement..
Danny
Never Think Impossible
If you find my answer helpful then please add to my reputation
-
Aug 26th, 2005, 02:28 PM
#5
Re: INSERT versus ADDNEW
Recordsets are very slow and take up more memory as they are increasingly added to. Insert Into statements all the way too.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 26th, 2005, 02:30 PM
#6
Re: INSERT versus ADDNEW
 Originally Posted by dannymking
... Even more efficient if your value source can be loaded into a table beforehand ...
What in the world would that mean? I wish you can explain.
-
Aug 26th, 2005, 02:38 PM
#7
Re: INSERT versus ADDNEW
Maybe he means to populate the table via Insert Into statements and then poulate a rs.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 26th, 2005, 02:39 PM
#8
Re: INSERT versus ADDNEW
 Originally Posted by RobDog888
Recordsets are very slow and take up more memory ...
Recordsets are slower but not very much - it depends on the size, type, cursor location. Under surcumstances using AddNew would be better choice as you can immediatley CancelUpdate for a specific record.
-
Aug 26th, 2005, 02:41 PM
#9
Re: INSERT versus ADDNEW
Not necessarily. You can use the connection objects .BeginTransaction to start a trans and then Insert Into statements can be executed. If all goes well then you can do a oCn.CommitTransaction. And if an issue occurs then a oCnn.RollbackTransaction. 
You can do it on a single insert statement or like a batch commit if you want.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 26th, 2005, 02:44 PM
#10
Re: INSERT versus ADDNEW
And you will be creating transactions for each record while in some loop or something? Transactions are good when you do bulk insert/update but for a single record often is a waste.
-
Aug 26th, 2005, 02:47 PM
#11
Re: INSERT versus ADDNEW
Just showing an alternative to .CancelUpdate
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 26th, 2005, 02:54 PM
#12
Re: INSERT versus ADDNEW
I meant that if the values were to come from something like a text file, or spreadsheet or some other importable source then the insert into would only need to be ran once and would take less code...
Danny
Never Think Impossible
If you find my answer helpful then please add to my reputation
-
Aug 26th, 2005, 02:56 PM
#13
Thread Starter
PowerPoster
Re: INSERT versus ADDNEW
Thanks for the input, folks. I have begun converting a lot of ADDNEWs to INSERTs. Some of you may remember my problem with the db not writing all the record to the database (some fields are written, others are not). Since I converted those 2 transactions, I have not had a single instance of that occurance. It gave me the idea to convert all the ADDNEWs. I was looking for opinions. Looks like I am making the right choice.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|