简体   繁体   English

使用C#使用OleDb解析CSV-错误列包含双引号中未装载在数据表中的值

[英]Parsing CSV using OleDb using C# - Error column contain values with in double quotes those are not loaded in datatable

I am using OleDb to convert csv file as data table in c#. 我正在使用OleDb将csv文件转换为c#中的数据表。

I have problem with columns which has value having double quotes("), in this case after double quotes values and remaining columns values are not loaded in datatable. 我对具有双引号(“)的值的列有问题,在这种情况下,双引号值和剩余的列值未加载到数据表中之后。

here this is my code, 这是我的代码,

private DataTable ReadFileByDataTable (string sFileName) { 专用DataTable ReadFileByDataTable(字符串sFileName){
DataTable dtPOFileData = new DataTable(); DataTable dtPOFileData = new DataTable();

        using (OleDbConnection cnnOleDB = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Test;Extended Properties='text;HDR=Yes;FMT=Delimited;'"))
        {
            cnnOleDB.Open();

            using (OleDbDataAdapter adpPOFileData = new OleDbDataAdapter("SELECT * FROM ["test.csv"]", cnnOleDB))
            {
                adpPOFileData.Fill(dtPOFileData);
            }
        }

        return dtPOFileData;
    }

thanks in advance. 提前致谢。

I have tried this delimiter option and solve my problem OleDbConnection cnnOleDB = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\Test;Extended Properties='text;HDR=Yes;FMT=Delimited(,)';'" 我已经尝试使用此定界符选项并解决了我的问题OleDbConnection cnnOleDB = new OleDbConnection(“ Provider = Microsoft.Jet.OLEDB.4.0; Data Source = D:\\ Test; Extended Properties ='text; HDR = Yes; FMT = Delimited(, ) ';'”

here full version of the code, 这里是完整版本的代码,

private DataTable ReadFileByDataTable (string sFileName) { DataTable dtPOFileData = new DataTable(); 专用DataTable ReadFileByDataTable(字符串sFileName){DataTable dtPOFileData = new DataTable();

    using (OleDbConnection cnnOleDB = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Test;Extended Properties='text;HDR=Yes;FMT=Delimited(,)';"))
    {
        cnnOleDB.Open();

        using (OleDbDataAdapter adpPOFileData = new OleDbDataAdapter("SELECT * FROM ["test.csv"]", cnnOleDB))
        {
            adpPOFileData.Fill(dtPOFileData);
        }
    }

    return dtPOFileData;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用C#使用OleDb解析CSV - Parsing CSV using OleDb using C# C#解析包含使用正则表达式的双引号和单引号的字符串 - C# Parsing Strings that contain Double Quotes and Single Quotes using Regular Expression 使用C#将每个字段都用CSV文件括在双引号中 - Enclosing every field with double quotes in CSV file using c# 使用正则表达式在c#中使用单引号,双引号或无引号拆分csv文件 - Split csv file with single quotes, double quotes or no quotes in c# using regular expression 列之一的CSV文件同时包含整数和字符串值,如果未加载字符串值,则使用C#Oledb上传 - CSV file one of the column contains both integer and string values, uploading using C# Oledb provide string values are not loading C#使用OleDb导入CSV - C# Importing CSV using OleDb excel到DataTable使用带连字符的csv邮政编码不使用C#OLEDB显示 - excel to DataTable to csv Zip Codes w/ Hyphens not showing using C# OLEDB 使用查询之间的范围将输入双精度数与数据表的字符串列值进行比较(在SQL查询中对数据表C#的Linq进行查询) - Compare input double with datatable string column values within a range using between query(SQL query to Linq on datatable c# ) 使用C#将可插入双引号的字符串插入MySQL数据库表 - Inserting into a MySQL database table, using C#, a string that can contain double quotes <a>使用C#</a>添加双引号 - Adding double quotes in <a> using C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM