从Unicode格式的csv或txt文件中读取 [英] Reading from a csv or a txt file in Unicode format

查看:309
本文介绍了从Unicode格式的csv或txt文件中读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好


我写了一个小代码,用于从txt或csv文件中读取记录,但当我尝试从unicode的txt或csv文件中读取,我得到以下错误


没有给出一个或多个必需参数的值........这错误收到以下行


dtadpt.Fill(DataSet.Tables( " table2" ))



从文件中读取的代码如下


Dim dtrow As DataRow


Dim cmdtxt,file,fs,path


Dim dtadpt As System.Data.OleDb.OleDbDataAdapter


Dim AccessCommand As System.Data.OleDb.OleDbCommand


Dim AccessConn As System.Data.OleDb.OleDbConnection


fs = CreateObject( " scripting.filesystemobject"


file = fs.getfilename(TextBox1。文本)


path = fs.getparentfoldername(TextBox1.Text)


AccessConn = System.Data.OleDb.OleDbConnection( " Provider = Microsoft.Jet.OLEDB.4.0;" ; & _


" Data Source =" &路径& " ;;" & " Extended Properties ="" text; HDR = YES; FMT = Delimited""


对于 每个 dtrow In DataSet.Tables( " table1" )。行


Dim id



id = dtrow.Item( " id"

cmdtxt = " Select * from" &档案& "其中id =" & id


AccessCommand = New System.Data.OleDb.OleDbCommand(cmdtxt,AccessConn)


dtadpt.SelectCommand = AccessCommand


下一步


DataSet.Tables.Add(" table2"


dtadpt。填充(DataSet.Tables( " table2" ))


如果我选择的是ANSI格式的csv或txtfile,则此代码有效。但我想读取unicode文件,因为我有一些unicode格式的信息,我想存储


任何想法如何这样做可能


解决方案

您好,

要使用OLEDB读取unicode格式的文本文件,应在schema.ini文件中指定CharacterSet(Unicode)。

请参阅以下URL以获取更多信息。
http://www.techshirly.blogspot.com/

结果,由于

Hello there

I have written a small code that is used to read records from a txt or a csv file, but when i try to read from a txt or csv file which is in unicode, i get the following error

No value given for one or more required parameters........this error is recieved on the following line

dtadpt.Fill(DataSet.Tables("table2"))

 

The code for reading from a file is as follows

Dim dtrow  As DataRow

Dim cmdtxt, file, fs, path

Dim dtadpt As New System.Data.OleDb.OleDbDataAdapter

Dim AccessCommand As System.Data.OleDb.OleDbCommand

Dim AccessConn As System.Data.OleDb.OleDbConnection

fs = CreateObject("scripting.filesystemobject")

file = fs.getfilename(TextBox1.Text)

path = fs.getparentfoldername(TextBox1.Text)

AccessConn = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _

"Data Source=" & path & ";" & "Extended Properties=""text;HDR=YES;FMT=Delimited""")

For Each dtrow In DataSet.Tables("table1").Rows

Dim id

id = dtrow.Item("id")

cmdtxt = "Select * from " & file & " where id = " & id

AccessCommand = New System.Data.OleDb.OleDbCommand(cmdtxt, AccessConn)

dtadpt.SelectCommand = AccessCommand

Next

DataSet.Tables.Add("table2")

dtadpt.Fill(DataSet.Tables("table2"))

this code works if i choose a a csv or txtfile which is in ANSI format. But i want to read from a unicode file because i have some information in that unicode format that i want to store

any idea how this can be possible

解决方案

Hi,

To read the unicode formatted text file using OLEDB, the CharacterSet(Unicode) should be specified in the schema.ini file.

Please refer the below URL for more information.
http://www.techshirly.blogspot.com/


Thanks


这篇关于从Unicode格式的csv或txt文件中读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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