Click here to Skip to main content
15,881,712 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can someone please take a look,
I do not know why in the last csv line the last 4 columns are cut off?!

Maybe that helps if I briefly describe the process.

What I have tried:

//Line Break

builder.AppendLine("\r\n\n");
}
using (StreamWriter sw = new StreamWriter(csvFilePath))

{
sw.WriteLine(builder);
sw.Flush();
}
Posted
Updated 27-Nov-17 2:15am
v5
Comments
Tomas Takac 20-Nov-17 2:51am    
You mean the three columns you add within the "if"? Did you try to debug it?
Tomas Takac 20-Nov-17 6:06am    
You need to debug it and check what's the value of data._Stu.
Ralf Meier 20-Nov-17 2:52am    
Which is "the last csv line the last 3 columns" inside your code ?
What does your Debugger says ?
Ralf Meier 20-Nov-17 3:34am    
Then you should look what your variable(s) contain AND which type of variable they contain ...
Sinisa Hajnal 20-Nov-17 5:16am    
Put a try catch around the block and get concrete error. My guess would be your if values aren't set.

1 solution

You need to think about where to use builder.AppendLine or builder.Append depending if you need a NewLine at the end or not.
Because of this, the optional part is on a NewLine instead of the end of previous one.
C#
builder.AppendLine(data._Vo + "," + data._Bi + "," + data._Dau);

----
In case you wonder why your code takes so much time to write the csv file, the answer is because of this:
C#
data._Id + "," + quote + data._Na1 + quote + "," + data._Sche + "," + data.bdi_Hi2 + "," + data.Wei + "," + data.Stz + "," + data.Da + "," + data.Vo + "," + data.Bi + "," + data._Ad1 + "," + data.bpt_Ad2 + "," + data._Str + "," + data._AdZ + "," + data._Te1 + ","  + data._or + "," + data._Ges + "," + data._lun + "," + data.p_Na + "," + data.p_Ad + "," + data.p_Ad2 + "," + data.p_T1 + "," + data.p_Mo + "," + data.p_Ml + ","             + data.p_Io + "," + data.z_N + "," + data.z_Ad1 + "," + data.z_Ad2 + "," + data.z_PZ + "," + data.z_O + "," + data.z_T1 + "," + data.z_Ml + "," + data.z_Ma + "," + data._len1 + "," + data._len2 + "," + data._len3 + "," + data._Stu + "," + data._Dum + ","

You are building a string with 70+ strings without using a StringBuilder class.
even worse, you build this string to feed a StringBuilder variable.
You will hugely improve speed and memory footprint by feeding each pieces directly in the StringBuilder variable.
C#
builder.Append(data._Id + ",");
builder.Append(quote + data._Na1 + quote + ",");
builder.Append(data._Sche + ",");
...
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900