导入Csv文件Oledb C#

导入Csv文件Oledb C#,c#,csv,oledb,C#,Csv,Oledb,大家好,有人能给我这个问题的解决方案吗?我必须用c#导入csv文件,但我在这个屏幕截图中遇到了这个问题 单独的betwenn列是“”,但在数据中有一行包含“Mohamed,我看不到您的屏幕截图,但可以指向通用列表并创建一个类来表示数据。您需要从“项目”菜单添加引用 Microsoft.VisualBasic 系统配置 窗台 我包含了一段代码中的代码,我正在执行此操作: using System; using System.IO; using System.Collections.Gener

大家好,有人能给我这个问题的解决方案吗?我必须用c#导入csv文件,但我在这个屏幕截图中遇到了这个问题


单独的betwenn列是“”,但在数据中有一行包含“

Mohamed,我看不到您的屏幕截图,但可以指向通用列表并创建一个类来表示数据。您需要从“项目”菜单添加引用

  • Microsoft.VisualBasic
  • 系统配置
  • 窗台
我包含了一段代码中的代码,我正在执行此操作:

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualBasic.FileIO;

namespace CsvToListExp
{
class Program
{
    public static void Main(string[] args)
    {
        // HARD_CODED FOR EXAMPLE ONLY - TO BE RETRIEVED FROM APP.CONFIG IN REAL PROGRAM
        string hospPath = @"C:\\events\\inbound\\OBLEN_COB_Active_Inv_Advi_Daily_.csv";
        string vendPath = @"C:\\events\\outbound\\Advi_OBlen_Active_Inv_Ack_Daily_.csv";

        List<DenialRecord> hospList = new List<DenialRecord>();
        List<DenialRecord> vendList = new List<DenialRecord>();
        //List<DenialRecord> hospExcpt = new List<DenialRecord>();  // Created at point of use for now
        //List<DenialRecord> vendExcpt = new List<DenialRecord>();  // Created at point of use for now

        using (TextFieldParser hospParser = new Microsoft.VisualBasic.FileIO.TextFieldParser(hospPath))
        {
            hospParser.TextFieldType = FieldType.Delimited;
            hospParser.SetDelimiters(",");
            hospParser.HasFieldsEnclosedInQuotes = false;
            hospParser.TrimWhiteSpace = true;

            while (!hospParser.EndOfData)
            {

                try
                {
                    string[] row = hospParser.ReadFields();
                    if (row.Length <= 7)
                    {
                        DenialRecord dr = new DenialRecord(row[0], row[1], row[2], row[3], row[4], row[5], row[6]);
                        hospList.Add(dr);
                    }
                }
                catch (Exception e)
                {
                    // do something
                    Console.WriteLine("Error is:  {0}", e.ToString());
                }
            }
            hospParser.Close();
            hospParser.Dispose();
        }


        using (TextFieldParser vendParser = new Microsoft.VisualBasic.FileIO.TextFieldParser(vendPath))
        {
            vendParser.TextFieldType = FieldType.Delimited;
            vendParser.SetDelimiters(",");
            vendParser.HasFieldsEnclosedInQuotes = false;
            vendParser.TrimWhiteSpace = true;

            while (!vendParser.EndOfData)
            {
                try
                {
                    string[] row = vendParser.ReadFields();
                    if (row.Length <= 7)
                    {
                        DenialRecord dr = new DenialRecord(row[0], row[1], row[2], row[3], row[4], row[5], row[6]);
                        vendList.Add(dr);
                    }
                }
                catch (Exception e)
                {
                    // do something
                    Console.WriteLine("Error is:  {0}", e.ToString());
                }
            }
            vendParser.Close();
            vendParser.Dispose();
        }

        // Compare the lists each way for denials not in the other source
        List<DenialRecord> hospExcpt = hospList.Except(vendList).ToList();
        List<DenialRecord> vendExcpt = vendList.Except(hospList).ToList();
    }
}
}
使用系统;
使用System.IO;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用Microsoft.VisualBasic.FileIO;
命名空间CsvToListExp
{
班级计划
{
公共静态void Main(字符串[]args)
{
//硬编码(仅用于示例)-在REAL PROGRAM中从APP.CONFIG检索
字符串hospPath=@“C:\\events\\inbound\\OBLEN\u COB\u Active\u Inv\u Advi\u Daily\u.csv”;
字符串vendPath=@“C:\\events\\outbound\\Advi\u OBlen\u Active\u Inv\u Ack\u Daily\u.csv”;
List hospList=新列表();
List vendList=新列表();
//List hospExcpt=new List();//目前在使用点创建
//List vendexpt=new List();//目前在使用点创建
使用(TextFieldParser hospParser=new Microsoft.VisualBasic.FileIO.TextFieldParser(hospPath))
{
hospParser.TextFieldType=FieldType.Delimited;
hospParser.SetDelimiters(“,”);
hospParser.hasfieldsensclosedinquotes=false;
hospParser.TrimWhiteSpace=true;
而(!hospParser.EndOfData)
{
尝试
{
字符串[]行=hospParser.ReadFields();

如果(row.Length),请阅读,特别是我的问题是CSV文件中的group by,无法使用linq,因为我使用的是framework 2.0