.NETGURU
String concatenation is slow... Faster method for Bulk SQL string?
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.vb.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Lucas Tam
Hi all,

I'm concatenating a large SQL string for updating a table. There are >
80,000 commands (rows) in the SQL string. VB.NET seems to be *VERY* slow at
string concatenation when the string gets large...

Is it possible to execute a SQL command from a text file? .NET can
streamwrite extremely fast so I was thinking of writing all the commands to
a text file then executing the text file.

Is this possible? Or do I have to read the File back into a string and
submit it to ADO.NET?

Thanks.

--
Lucas Tam (Click here to reveal e-mail address)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Reply to this message...
 
    
Cor Ligthert
Hi Lucas,

Try to avoid the concatination of strings in anyway even with stringbuilder,
beside that it is not the right way, it is as well not good for security.

Try to use the command.parameters for that.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatasqlclientsqlparameterclasstopic.asp

Browse from here how to make the SQL string for that.

I hope this helps?

Cor

Reply to this message...
 
    
Lucas Tam
Lucas Tam <Click here to reveal e-mail address> wrote in
news:Xns955FEE9CDD16Cnntprogerscom@140.99.99.130:

[Original message clipped]

Just gave StringBuilder a try... and it's MUCH faster.

I read somewhere that you shouldn't reuse the Stringbuilder object since
Strings are immutable. What is the best way to destory the string object
for reuse in a loop?

Thanks.

--
Lucas Tam (Click here to reveal e-mail address)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Reply to this message...
 
    
Imran Koradia (VIP)
Per documentation, String Objects are immutable while StringBuilder Objects
are mutable. So as long as you keep appending the sql statements to the
stringbuilder object, you should be fine - you shouldn't need to destroy any
objects then. At the very end when you're done building the entire sql, you
can just do ToString and execute it.

hope that helps..
Imran.

"Lucas Tam" <Click here to reveal e-mail address> wrote in message
news:Xns955FEFEB2965Dnntprogerscom@140.99.99.130...
[Original message clipped]

Reply to this message...
 
    
Herfried K. Wagner [MVP] (VIP)
* Lucas Tam <Click here to reveal e-mail address> scripsit:
[Original message clipped]

What do you mean by reusing the stringbuilder? Sure, you can reuse an
instance of stringbuilder as it's not immutable.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Reply to this message...
 
 
System.Text.StringBuilder




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification