?
Solved

Problem with  StreamWriter not writting  the  whole line

Posted on 2013-05-16
5
Medium Priority
?
597 Views
Last Modified: 2013-05-16
I'm using a string reader to go through a CSV file parsing it and rebuilding a new extract. HAving problems with wtriting to csv  (Using excel 2003, VB 2010.)
 Dim sWriter As StreamWriter = New StreamWriter("c:\temp\test.csv")
 Dim filePath As String = "c:\temp\test.csv"

 Using dReader As New StreamReader(filePath)
            Dim line As String
            Dim myFlag As Boolean
            sWriter.Write("col1","col2","col3","col1","col2","col3")
            sWriter.WriteLine()  
 ' have to use this extra  sWriter.WriteLine()    or no line break  the date filed  tags along on first row and just  sWriter.WriteLine()    does not give a line breck.


 line = dReader.ReadLine()

items = line.Split(",".ToCharArray())
                           col1= (items(1).ToString)
                            col2 =(myOrdNo.Substring(0, 1) + "0000" + Mid(items(1).ToString, 3, 7))
                            col3 = (myOrdNo.Substring(0, 1) + "0")

sWriter.Write(myTESTDATE, col1, col2, col(3).ToString)   ' I tried tostring no difference....


I get thehearder Row
then only the first  col date value when I inspect the row data before it loads it's there....

I even tried (myTESTDATE, "test","test","test",) same results...
Any ideas anyone?




Does anyone know a better way?
0
Comment
Question by:cin_champ
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 2000 total points
ID: 39171961
you need to build the output string EXACTLY as it is to be written to the file - that is, you add the commas yourself:

string output = string.Empty;
output = "col1" + "," +"col2" + "," + "col3" + "," + "col4" + "," + "col5";
sWrite.WriteLine(output);

AW
0
 

Author Comment

by:cin_champ
ID: 39172128
AW,
How do I string it properly if I have values?

 OUTPUT = " & myTESTDATE.TOSTRING &" + "," + "&myOPERATOR.tostring&" + "," + " &myEVNAME&"

this does does not work.... any sugestions on how I pass my values?

Thank You so much!
CJ
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 39172161
OUTPUT = myTESTDATE.TOSTRING + "," + myOPERATOR.tostring + "," + myEVNAME

you concatenate the ACTUAL values, with the comma separators

AW
0
 

Author Closing Comment

by:cin_champ
ID: 39172191
Thank You

this worked for me (no first +:


 OUTPUT = col1" + "," +"col2" + "," + "col3" + "," + "col4" + "," + "col5
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 39172214
Glad to be of assistance

AW
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question