如何从 Access 数据库中的文本文件(未分隔)导入记录?
我只是想找出一个使用 Microsoft.Jet.Oledb Provider 4.0 和 Vb.net 从文本文件到 access 数据库的记录导入程序。这看起来很容易,但我的问题不同。在文本文件中,记录没有分隔。我是新手,所以这对我来说太难了。请给出一些提示来解决这个问题。
Format of the text file:
Field Name & Size
Date[Date,ShortDate]FirstName[20]LastName[20]Sex[1]Age[2]
Records
02062011john……………..little………………M15
…
…
…
我可以在使用流阅读器读取文本文件时以编程方式放置分隔符,然后将整个文件导入数据库吗?任何建议
I am just trying figure out a record import program from text file into access database using Microsoft.Jet.Oledb Provider 4.0 and Vb.net. And it seems easy but my problem is different. In the text file, records are not delimited. I am a newbie so it became too hard for me. Please give some hint to solve this issue.
Format of the text file:
Field Name & Size
Date[Date,ShortDate]FirstName[20]LastName[20]Sex[1]Age[2]
Records
02062011john……………..little………………M15
…
…
…
Can I put delimiter programmatically while reading the text file using stream reader and later simply import the whole file in DB. Any suggestions
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种选择是使用 TextFieldParser 类:
http:// msdn.microsoft.com/en-us/library/microsoft.visualbasic.fileio.textfieldparser.aspx
我在此示例中使用了 StringReader,但您也可以轻松使用StreamReader 或仅在 TextFieldParser 构造函数中使用文件名。
或者,您可以使用 StreamReader 和 String.Substring 方法的组合来获取各个字段。
One option is to use the TextFieldParser class:
http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.fileio.textfieldparser.aspx
I used a StringReader in this example, but you could just as easily use a StreamReader or just use the filename in the TextFieldParser constructor.
Or you could use a combination of the StreamReader and the String.Substring method to get the individual fields.
不是用空格分隔的吗?您对文本文件有任何限制吗,例如从第一个字符到第 100 个字符是名字等?如果是,您可以根据这些约束来打破文本。
Is it not space delimited? Do you have any constraints on text file like for example from first character till 100th character is first name etc? If yes you can break the text on the basis of those constraints.