How to efficiently write to file from SQL datareader in c#?

前端 未结 7 1210
隐瞒了意图╮
隐瞒了意图╮ 2020-12-15 00:14

I have a remote sql connection in C# that needs to execute a query and save its results to the users\'s local hard disk. There is a fairly large amount of data this thing ca

相关标签:
7条回答
  • 2020-12-15 01:05

    Keeping your original approach, here is a quick win:

    Instead of using String as a temporary buffer, use StringBuilder. That will allow you to use the function .append(String) for concatenations, instead of using the operator +=.

    The operator += is specially inefficient, so if you place it on a loop and it is repeated (potentially) millions of times, the performance will be affected.

    The .append(String) method won't destroy the original object, so it's faster

    0 讨论(0)
提交回复
热议问题