|
-
Dec 8th, 2014, 04:39 AM
#1
Thread Starter
Junior Member
VB2010: Dealing with CSV files
Hi,
I have a two column CSV file embedded in a VB2010 project. I'd like the user to enter some text into a text box which matches with column A of the CSV file - the code should then return the corresponding text in Column B of the cvs file.
I'm a little confused on the best method of dealing with the CSV file..an array? convert to some sort of DB? etc etc.
The only proviso is that as the CSV files change frequently, I need a method that can act 'on the fly' rather than laborious first time job.
Can anyone suggest a good method with code example please?
Thanks
David
-
Dec 8th, 2014, 05:09 AM
#2
Re: VB2010: Dealing with CSV files
You could use the TextFieldParser class, designed for this sort of thing. Once you read in the file, save the filedate/size into a variable and put it into a datatable. Each time you need to process the data, check if the filedate/size has changed, if so reimport, or use the existing datatable.
-
Dec 8th, 2014, 11:30 AM
#3
Hyperactive Member
Re: VB2010: Dealing with CSV files
If there are only the two columns and you want the data in one to point to the data in the other column, then I'd think a Dictionary(Of T, T) would be the best data storage for what you need. In a Dictionary, the items are set up as Key-Value pairs that you can easily get the data you need using the Key to retrieve the associated value:
Code:
myValue = myDictionary(myKey)
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|