Click here to Skip to main content
16,015,583 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am a student and I am going to create a window application with ms access that will read data from a notepad file and and store it in the database.

Notepad file will be in specific foramt as:

name|age

If my reader finds 'name' and there after a '|' then next data should go to age section.
I am expecting some tips or kind of coding help so that I can make my application.

Regards,
[EMAIL DELETED]

[edit]Never post your email address in any forum, unless you really like spam! If anyone replies to you, you will receive an email to let you know. - OriginalGriff[/edit]
Posted
Updated 16-Jan-11 21:42pm
v3
Comments
Dalek Dave 17-Jan-11 3:43am    
Edited for Grammar and Readability.

1 solution

The easiest way is to read the file in using the ReadAllLines method:
string[] lines = File.ReadAllLines(path);
You can then process each line individually:
foreach (string line in lines)
And process each line into two sections:
string[] sections = line.Split('|');
Check you have two sections (or there is an input problem), and then use them:
string name = sections[0];
string age = sections[1];
All you have to do then is save them to your database.

Note: You have nearly all the code you need there: I have left you some work in deciding how to "bolt it all together". Since it is your homework, it is only fair you do some of the work! :laugh:
 
Share this answer
 
Comments
Dalek Dave 17-Jan-11 3:43am    
Good Call, Griff.
arshad alam 19-Jan-11 4:08am    
hi Dave,

i am very thankful to you,its working fine, i am adding a datatable so that i can insert all the rows of section array. i am dealing with huge data. it has 44 column and its txt file size is 20 MBs. first time when i fill the datatable in the datagridview , its fine . i have a cancel button. on click . i am clearing the datatable. when i do same the proccess in after clicking the cancel button, it is taking more time to display than previous time. what can be possiblities to handle this.
OriginalGriff 19-Jan-11 5:18am    
I think your reply contains the reasons quite well:
"44 column"
"20Mb"
"datagridview"

Now think about the user. How many rows?
If every entry in every column has ten characters, that is 47,000 rows.

Do you want to sit there and look at 47,000 rows of similar looking data, trying to find the row you want?
Don't load it all into a datatable, or a datagridview, or anything else.
Read it from your text file, and write it to your database using SQL or LINQ.
Then only display data a page at a time. Give him search facilities.

Why does it slow down? Probably because it calls in the garbage collector to get rid of all the old stuff to make room for the new...
arshad alam 19-Jan-11 6:38am    
how can i impliment LINQ to Display or save data .. will you kindly demonstrate it ??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900