Dealing with CSV

M

MFRASER

I have to import a CSV file into my system and I am currently spliting the
rows and then the columns and inserting that data into my objects. This is
very slow, does anyone have another way of doing this?

Here is my psuedo code

//Reload DetailIDs

char[] Newline = System.Environment.NewLine.ToCharArray();

string[] Rows = strData.Split(Newline);

int MaxRows = Rows.GetUpperBound(0);


//Loop through each row and parse out first column

for (i = 0; i <= MaxRows ; i++)

{

string ColumnData = Rows.Trim();

if (ColumnData.Length > 0)

{

string[] Cols = ColumnData.Split(',');

//Get each Value

for(int tmpCounter = ColValIndex; tmpCounter <= ColMax; tmpCounter++)

{

//Do something

}

}

}
 
P

Pradeep M M

HI,
Weee that is a huge way to solve the csv file? what
would you do if you had around 60,000 records and above.
What I would suggest is why dont you put the csv file into
a dataset and then do the required functioning from
dataset than taking individual row and column.

CSV - > DataSet --> do the reqd changes..

Cheers,
Pradeep M M
 
M

MFRASER

Ok. Does anyone now how I can import a CSV to a dataset. The problem with
my XML files is that it is a CSV file inside of XML
Here is an example:


<XMLIntegration>9/10/2003 10:23:23 AM

<Schedule COLUMNS="StationName, Date_time, Item1, Item2, Item3, Item4,
Item5">

Columbia 1, 9/5/2003 0:00:00 AM, 164, 48, 0, 1, 1

Columbia 1, 9/5/2003 0:30:00 AM, 164, 48, 1, 1, 1

Columbia 1, 9/5/2003 1:00:00 AM, 164, 48, 2, 1, 1

Columbia 1, 9/5/2003 1:30:00 AM, 164, 48, 3, 1, 1

Columbia 1, 9/5/2003 2:00:00 AM, 164, 48, 4, 1, 1

Columbia 1, 9/5/2003 2:30:00 AM, 164, 48, 5, 1, 1

Columbia 1, 9/5/2003 3:00:00 AM, 164, 48, 6, 1, 1



</Schedule>

</XMLIntegration>

Pradeep M M said:
HI,
Weee that is a huge way to solve the csv file? what
would you do if you had around 60,000 records and above.
What I would suggest is why dont you put the csv file into
a dataset and then do the required functioning from
dataset than taking individual row and column.

CSV - > DataSet --> do the reqd changes..

Cheers,
Pradeep M M
-----Original Message-----
I have to import a CSV file into my system and I am currently spliting the
rows and then the columns and inserting that data into my objects. This is
very slow, does anyone have another way of doing this?

Here is my psuedo code

//Reload DetailIDs

char[] Newline = System.Environment.NewLine.ToCharArray();

string[] Rows = strData.Split(Newline);

int MaxRows = Rows.GetUpperBound(0);


//Loop through each row and parse out first column

for (i = 0; i <= MaxRows ; i++)

{

string ColumnData = Rows.Trim();

if (ColumnData.Length > 0)

{

string[] Cols = ColumnData.Split(',');

//Get each Value

for(int tmpCounter = ColValIndex; tmpCounter <= ColMax; tmpCounter++)

{

//Do something

}

}

}


.
 
N

Nicholas Paldino [.NET/C# MVP]

MFRASER,

I think there was an ODBC driver for text files that you could have used
for this. You can use the classes in the System.Data.Odbc namespace to
access this data by saving the CSV portion to a temp file, then reading what
you need from the temp file through the ODBC data provider.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

MFRASER said:
Ok. Does anyone now how I can import a CSV to a dataset. The problem with
my XML files is that it is a CSV file inside of XML
Here is an example:


<XMLIntegration>9/10/2003 10:23:23 AM

<Schedule COLUMNS="StationName, Date_time, Item1, Item2, Item3, Item4,
Item5">

Columbia 1, 9/5/2003 0:00:00 AM, 164, 48, 0, 1, 1

Columbia 1, 9/5/2003 0:30:00 AM, 164, 48, 1, 1, 1

Columbia 1, 9/5/2003 1:00:00 AM, 164, 48, 2, 1, 1

Columbia 1, 9/5/2003 1:30:00 AM, 164, 48, 3, 1, 1

Columbia 1, 9/5/2003 2:00:00 AM, 164, 48, 4, 1, 1

Columbia 1, 9/5/2003 2:30:00 AM, 164, 48, 5, 1, 1

Columbia 1, 9/5/2003 3:00:00 AM, 164, 48, 6, 1, 1



</Schedule>

</XMLIntegration>

Pradeep M M said:
HI,
Weee that is a huge way to solve the csv file? what
would you do if you had around 60,000 records and above.
What I would suggest is why dont you put the csv file into
a dataset and then do the required functioning from
dataset than taking individual row and column.

CSV - > DataSet --> do the reqd changes..

Cheers,
Pradeep M M
-----Original Message-----
I have to import a CSV file into my system and I am currently spliting the
rows and then the columns and inserting that data into my objects. This is
very slow, does anyone have another way of doing this?

Here is my psuedo code

//Reload DetailIDs

char[] Newline = System.Environment.NewLine.ToCharArray();

string[] Rows = strData.Split(Newline);

int MaxRows = Rows.GetUpperBound(0);


//Loop through each row and parse out first column

for (i = 0; i <= MaxRows ; i++)

{

string ColumnData = Rows.Trim();

if (ColumnData.Length > 0)

{

string[] Cols = ColumnData.Split(',');

//Get each Value

for(int tmpCounter = ColValIndex; tmpCounter <= ColMax; tmpCounter++)

{

//Do something

}

}

}


.

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top