使用分隔符将数据从文本文件上传到Ms Access [英] Upload data from textfile into Ms Access which using delimiter

查看:79
本文介绍了使用分隔符将数据从文本文件上传到Ms Access的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我需要从textfile(*.txt)上传数据,该文件使用定界符作为数据的分隔符:-
例如:

Hye all,

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

07010000584|MY COMPANY SDN|752|PRESLEY ROAD|TEXTILES|BLUE|3873.50


使用分隔符将此文件上传到数据库的代码是什么?是否需要先上传到数据集?

希望定界符中的每个值就像列中的数据一样.


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.

推荐答案

一种方法是使用例如use File.ReadAllLines [
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...

}


您是否需要以编程方式进行?如果您不这样做,我建议您使用Excel打开它并将其另存为Excel文件,然后将该文件导入Access.如果这样做,请选择单元格,然后在数据"选项卡下,选择文本到列",然后按照向导将其转换为单元格.
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.


这篇关于使用分隔符将数据从文本文件上传到Ms Access的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆