473,408 Members | 2,888 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,408 software developers and data experts.

How to recall csv data when there are multiple fields?

110 100+
I'm working on a Address book that has 4 fields: Name, Email, Phone, Birthday. I have so far been able to get the program to add a new entry in the csv when you click add (it currently does no sort of verification). Right now I am trying to get the search function to work which I am having trouble with. If all I had to do was read the file in with streamreader I can do that, but how do I read in an entry split on commas so it can store each split read into a field. I need those split reads stored in fields to compare against the searched term. Thus far I have something that looks like this:
Expand|Select|Wrap|Line Numbers
  1.     string[] fields;
  2.            string recordIn;
  3.  
  4.             recordIn = reader.ReadLine();
  5.  
  6.  
  7.              while(recordIn != null)
  8.             {
  9.                 string line = reader.ReadLine();
  10.                 fields = line.Split(DELIM);
  11.                 entryObject.Name = fields[0];
  12.                 entryObject.Email = fields[1];
  13.                 entryObject.Phone = fields[2];
  14.                 entryObject.Birthday = fields[3];
  15.  
  16.  
  17.  
  18.  
  19.                 if (entryObject.Name == searchTerm || entryObject.Email == searchTerm
  20.                     || entryObject.Phone == searchTerm || entryObject.Birthday == searchTerm)
  21.                 {
  22.  
  23.                     string searchResults = string.Format("Name:\t{0}\nEmail:\t{1}\n"+
  24.                         "Phone:\t{2}\nBirthday:\t{3}"
  25.                         ,entryObject.Name, entryObject.Email,
  26.                         entryObject.Phone, entryObject.Birthday);
  27.  
  28.                     MessageBox.Show(searchResults, "Entry Found", MessageBoxButtons.OK);
  29.                     entryFound = true;
  30.                     break;
  31.                 }               
  32.             }
  33.  
The problem if as far as I can tell is that the program reads a line, then it enters a while loop but it just sits and compares the first line it read in never failing a test because it just does the same thing over and over. Is that right? I feel like if I could read the entire csv then do something like:
Expand|Select|Wrap|Line Numbers
  1. for(int i = 0; i < recordIn.Length; i++)
  2. string[] line = reader.readline();
  3.  
Then it would look at the whole file and say, there are this many entries, we need to read the next line until we have read each line and compared the fields. Problem is I don't know exactly how I would do that or if it is the most practical way to do what I am trying to achieve.
Again I'm trying to read the entries of a csv and see if any of the 4 fields per entry match the searched term.

Any suggestions are greatly appreciated.
Nov 15 '10 #1
0 1061

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jonathan | last post by:
I've seen this subject here in a similar fashion, but not in a fashion that can easily be accomplished for my purpose. Simply put, I have a form, I have about 2 dozen fields on this form, that I...
2
by: PPT33R | last post by:
The MS Access website is very unhelpful on this topic, and I cannot find anything in my Googling to find a hint. I am working with very large, existing data sets that consist of multiple fields....
5
by: jlicciardi | last post by:
I have a table with a field that has ( a sample ) 13767;38355;520270-1; 44795;38355;110818; 13981;38355;563550; as data. I need to extract the last set of numbers in each row. I have tried...
1
by: Randy | last post by:
I have trying to figure out the above topic. Can someone help me with this? I need for staff to be able to go to a dialog box or a form and then be able to enter data in mutliple fields and...
3
by: mkjets | last post by:
I have worked for hours on trying to find a solution and have not figured it out. I am working in Access 2003. I need to create a query that takes values from 1 table and displays them in...
4
by: HLCruz via AccessMonster.com | last post by:
I am working with a database that has client information separated in to 4 related tables - tFolder, tAddress, tEmail, tPhone number. In addition there are related tables tGifts and tCalls. The...
5
jimleon
by: jimleon | last post by:
I have a table of customers business categories with 13 fields - customer, category1, category2, ....... category12. The first field contains the customers name and the next 12 contain categories,...
2
by: Nathan Sokalski | last post by:
I have a Repeater that uses a DataSource that has multiple fields. When the values of these fields is displayed in the Repeater, there are fields that are used in combination with other fields as...
482
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if this is more of a coldfusion problem or a javscript problem. So if i asked my question in the wrong section let me know an all move it to the correct place. ...
3
by: Bigdaddrock | last post by:
I have a form that allows for input of new Customer Billing address fields (B1, B2, B3) as well as fields for the Shipping Address (S1, S2, S3). Sometimes these are the exact same! I have text...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.