473,287 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Help importing csv

Does anyone have a good way of importing a csv file into an object?

Entity1,123,22,red,blue
Entity2,123,22,red,blue
Entity3,123,22,red,blue
Entity4,123,22,red,blue
Entity5,123,22,red,blue

Currently I am spliting the data and then creating two for loops to loop
through the rows and then each column to assign the corresponding object
property.
Nov 15 '05 #1
2 1237
What about this option:

Add a new constructor to your object that takes a string in like so:
public void MyObject(string PropertiesCSV)
{
string[] ListOfProperties = PropertiesCSV.Split(",")
for(int i=0;i<ListOfProperties.GetUpperBound(0);i++)
{
this.var1 = ListOfProperties[i];
...
this.var99 = ListOfProperties[i]
}
}

Then all you need is one loop for each line in the CSV. I know this doesn't
exactly change your problem, it just shifts where the inner loop sits.

Hope this has been of some help.

Greg

"MFRASER" <mf*****@henwoodenergy.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Does anyone have a good way of importing a csv file into an object?

Entity1,123,22,red,blue
Entity2,123,22,red,blue
Entity3,123,22,red,blue
Entity4,123,22,red,blue
Entity5,123,22,red,blue

Currently I am spliting the data and then creating two for loops to loop
through the rows and then each column to assign the corresponding object
property.

Nov 15 '05 #2
Hi,

Take a look at http://www.opennetcf.org/Csv.asp
I'm using it and it works great.

Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"MFRASER" <mf*****@henwoodenergy.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Does anyone have a good way of importing a csv file into an object?

Entity1,123,22,red,blue
Entity2,123,22,red,blue
Entity3,123,22,red,blue
Entity4,123,22,red,blue
Entity5,123,22,red,blue

Currently I am spliting the data and then creating two for loops to loop
through the rows and then each column to assign the corresponding object
property.

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: qwweeeit | last post by:
The pythonic way of programming requires, as far as I know, to spread a big application in plenty of more manageable scripts, using import or from ... import to connect the various modules. In...
2
by: serge | last post by:
Using some VB sample code on the Internet I have the following that works well and exports a set of records to an XML file: Dim oCmd, sSQL, oDom Set oDom =...
1
by: Richard Holliingsworth | last post by:
Hello: Thanks for your quick response. I'm trying to import a new Excel file into an A2K table and it's truncating the data. One of the Excel columns is a text field that can be up to 2000...
21
by: Dan | last post by:
Hi, just ran into my first instance of a backend Access97 database not compacting. I'm getting the "MSACCESS.EXE has generated errors.." message on compact. I've narrowed it down to the largest...
9
by: Edward S | last post by:
I budget for a Project in an Excel sheet as illustrated below. The months below are usually a 2 year period i.e. 24 months, though it could be over 24 months depending upon a Project. I then...
13
by: Aladdin | last post by:
I have an MS Access form on which I have a listbox listing tables in that database. I want to be able to click on any of those tables and view its contents on the same form using subforms or any...
9
by: cheryl | last post by:
I am relatively new to programming in Access for a multi user environment, and am having trouble figuring out if there is a way to accomplish one of our user requests. I am working on a multi...
7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
4
by: larry | last post by:
Ok I'm a Python noob, been doing OK so far, working on a data conversion program and want to create some character image files from an 8-bit ROM file. Creating the image I've got down, I open...
3
by: rs387 | last post by:
Hi, I've found the following behaviour on importing a variable from a module somewhat odd. The behaviour is identical in Python 2.5 and 3.0b2. In summary, here's what happens. I have a...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.