CSV文件, 俗称"逗号分隔的文件", 读取CSV文件的方法可以使用IOStream按照即定格式读取... 我以为就这一种方法呢, 呵呵. 直到有一天.在www.ConnectionStrings.com上看到文本的连接 字符串: Text - ODBC
- OLE DB
- Standard:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\txtFilesFolder\;Extended Properties=""text;HDR=Yes;FMT=Delimited""" "HDR=Yes;" indicates that the first row contains columnnames, not data
- OLE DB
- Standard:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\txtFilesFolder\;Extended Properties=""text;HDR=Yes;FMT=Delimited""" "HDR=Yes;" indicates that the first row contains columnnames, not data
- Standard:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\txtFilesFolder\;Extended Properties=""text;HDR=Yes;FMT=Delimited""" "HDR=Yes;" indicates that the first row contains columnnames, not data
这里不是有csv么?呵呵,可以试一下啊, 试验结果很不错.可以使用ODBC来连接.把csv当作数据库, 感觉不错.(OleDb的没成功, 将Properties=text改为Properties=csv不好使 ,是不支持,还是我写错?) 因此这里提供一种方法.( 肯定不是我发明的哦 ), 使用ODBC连接方式,通过DataAdapter直接将 数据快速导入DataSet, 很方便.方法如下: public DataSet GetDataSetFromCSV(string filePath, string fileName) { string strConn = @"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq="; strConn += filePath; //filePath, For example: C:\ strConn += ";Extensions=asc,csv,tab,txt;" ; OdbcConnection objConn = new OdbcConnection(strConn); DataSet dsCSV = new DataSet(); try { string strSql = "select * from " + fileName; //fileName, For example: 1.csv OdbcDataAdapter odbcCSVDataAdapter = new OdbcDataAdapter(strSql, objConn); odbcCSVDataAdapter.Fill(dsCSV); return dsCSV; } catch(Exception ex) { throw ex; } }
|