Click here to Skip to main content
15,795,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hye all,

I need to upload data from textfile(*.txt) which using delimiter as separation for a data:-

What is the code to upload this file into database which using delimiter? Should it need to upload to dataset first?

I hope someone out there can help me..assume that each value in delimiter is just like a data in column.
Updated 2-Jan-12 20:52pm

One way is to use for example use File.ReadAllLines[^]. This would get you an array of string. For each string in array use Split method to break it into columns. After that use those string arrays as parameters for your insert statement. So something like:
string[] fileLines = System.IO.File.ReadAllLines("somefilename.txt");
foreach (string line in fileLines) {
   string[] cols = line.Split('|');
   // insert to database goes here...

Share this answer
Do you have to do it programmatically? If you don't, I would recomend opening it with Excel and saving it as an Excel file, then import that file into Access. If you do, select the cells, then under the Data tab, select Text to Columns and follow the wizard to convert it to cells.
Share this answer

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