Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Convert Comma Delimited Text File to XML

Posted on 2014-01-01
4
Medium Priority
?
537 Views
Last Modified: 2014-01-01
I need to convert a comma delimited text file to an XML that can be stored in a SQL Server table.

This is a sample of the text file:
There are 7 columns.
I am storing each col value in the values[] array.

AA.P,  20131227,  76.55,  78.95,  76.55,  78.95,  400
AADR,20131227,37.6,37.6,37.4,37.4,15800
AAMC,20131227,900,906.86,900,902,2100
AAU,20131227,1.13,1.16,1.1,1.15,137300
ACCU,20131227,28.35,28.35,28.28,28.3,3300
ACIM,20131227,62.11,62.11,62.11,62.11,300

This is the code I am using to count the lines:
     int intRowCounter1 = 0;
        FileStream fs1 = new FileStream(pstrSourceFile, FileMode.Open, FileAccess.Read);
        StreamReader sr1 = new StreamReader(fs1);

        string[] headers1 = sr1.ReadLine().Split(new char[] { ',' });
        string[] values1;
        string line1;

        while ((line1 = sr1.ReadLine()) != null)
        {
            intRowCounter1++;
        }

This is the code I am using to read each line:

FileStream fs = new FileStream(pstrSourceFile, FileMode.Open, FileAccess.Read);
        StreamReader sr = new StreamReader(fs);

        string[] headers = sr.ReadLine().Split(new char[] { ',' });
        string[] values;
        string line;
       
        //sr.ReadLine(); // Skips first line
        // Run "usp_getEODExtract" for each line

        while (intRowCount < intRowCounter1) // Skips 2 rows out of 1820 in AMEX EOD text file
   
        {
            line = sr.ReadLine();
            values = line.Split(new char[] { ',' });
            values[values.Length - 1] = values[values.Length - 1].Trim(new char[] { '"' });

Where do I go from here?

Thank you
0
Comment
Question by:Dovberman
[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
4 Comments
 
LVL 14

Accepted Solution

by:
Matti earned 2000 total points
ID: 39749869
MSAccess 2013 does this with it's import/export tools and you can connect to SQL from it.
No need to code just a few mouse clicks.

Matti
0
 

Author Comment

by:Dovberman
ID: 39749881
I will try and then give you feedback in 2 hours.

Thanks
0
 

Author Comment

by:Dovberman
ID: 39749890
I tried it on MS Access 2010.  It works perfectly.  I can also save the conversion as a job.

Thanks,
0
 

Author Closing Comment

by:Dovberman
ID: 39749891
Perfect, Thanks
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
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…

722 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