2016-07-22 2 views
-1

안녕하세요 사람이이 문제에 나에게 솔루션을 제공 할 수 있습니다, 전 C#을 사용 csv 파일을 가져올 수 있습니다하지만 난 ','스크린 샷 Screen수입 csv 파일 OLEDB C#을

별도의 betwenn 열은이 문제를 가지고 있지만, 데이터에 거기에 포함 된 행이 있습니다. "

+1

[도움말] 및 특히 [ask]를 읽어주십시오 – Steve

답변

0

모하메드, 스크린 샷을 볼 수 없지만 일반 목록을 가리키고 데이터를 나타내는 클래스를 만들 수 있습니다."프로젝트 "메뉴에서 참조를 추가해야합니다.

  • Microsof

    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(); 
        } 
    } 
    } 
    

    구글 TestFieldParser 및 방법, 속성을 찾습니다 t.VisualBasic

  • System.Configuration는
  • WindowsBase 어디 내가 코드 조각에서 코드를 포함하고

그 일을했다 및 생성자. 매우 다재다능하지만 계층이 다르기 때문에 느리게 실행됩니다. 구분 기호를 설정하고 따옴표로 싸인 필드를 처리하며 공백을 제거하는 기능이 있습니다.

+0

내 문제는 CSV 파일에서 그룹화되어 있으며 프레임 워크 2.0에서 작동하기 때문에 linq를 사용할 수 없습니다. –