Search:
Namespaces
Discussions
.NET v1.1
Feedback
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
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com