2017-04-27 59 views
0

我有这样的数据集:对象未在ScriptMain.CreateNewOutputRows()设置到对象的实例

001abcdefghijklmnopqrstuvwxyz 
003jfaoijfpoisajeoaijefoaijofija 
005;lksajdf;lkjsafd;lkjdf 
006;ldsjfa;ojfda;okjdfa;lkjfda 
009;akjfd;lakjfd;lajfd;lakjfd;la 
013jjsjfkdjf;ldsajfljkd;fjkdfjdfj 
001kfjfdjfkdjfosjisjfojesfljsijfesli <-- New Record 

我用一个脚本转换到这些行转变成列:

private StreamReader SR; 
    private string File1; 

    public override void AcquireConnections(object Transaction) 
    { 
     // Get the connection for File1 
     IDTSConnectionManager100 CM = this.Connections.OILFILEMGR; 
     File1 = (string)CM.AcquireConnection(null); 
    } 

    public override void PreExecute() 
    { 
     // Create a reader for File1 
     base.PreExecute(); 
     SR = new StreamReader(File1); 
    } 

    public override void PostExecute() 
    { 
     // Close the reader 
     base.PostExecute(); 
     SR.Close(); 
    } 

    public override void CreateNewOutputRows() 
    { 
     // Declare variables 
     string nextLine; 
     int LineNumber; 

     nextLine = SR.ReadLine(); 
     LineNumber = 1; 

     while (nextLine != null) 
     { 
       //MessageBox.Show(nextLine); 

       // Add a row 
       Output0Buffer.AddRow(); 

       Output0Buffer.APINumber = nextLine.Substring(5, 6); 

       Output0Buffer.County = nextLine.Substring(2, 3); 

       Output0Buffer.District = nextLine.Substring(14, 2); 

       nextLine = SR.ReadLine(); 
       LineNumber = LineNumber + 1; 

       while (nextLine.Substring(0, 2) != "01") 
       { 

         if (nextLine.Substring(0, 2) == "02") 
         { 
          Output0Buffer.LeaseNumber = nextLine.Substring(5, 5); 
         } 

         if (nextLine.Substring(0, 2) == "09") 
         { 
          Output0Buffer.FormationName = nextLine.Substring(5, 32); 
         } 

         if (nextLine.Substring(0, 2) == "13") 
         { 
          Output0Buffer.Latitude = nextLine.Substring(132, 10); 
          Output0Buffer.Longitude = nextLine.Substring(142, 10); 
         } 

        nextLine = SR.ReadLine(); 
        LineNumber = LineNumber + 1; 

       } 

     } 

    } 

} 

我试图将数据集拆分成一半,并且我注意到正在处理的行数也随着每个拆分一半而下降。这导致我相信代码有效,但不能正确地结束。我相信,当最后一个记录被记录时,不知何故脚本出错了。

我在这里错过了什么? 谢谢。

+0

如果您的数据库是SQL Server加载数据,因为它在数据库中,并在SQL脚本中使用PIVOT,它将更快地转换行到列[link](http://stackoverflow.com/questions/15745042 /有效变频-行到列 - 在-SQL服务器)。 – observer

+0

可以工作,但是给我的要求是它必须一次完成。没有分期。我解决了这个问题。它运行35K/s。对我来说足够好。 – arcee123

回答

0

经过许多修补之后,我碰到了这个C#.net主食。 如果你有一个空行,不要尝试Subset它。

我改变:

while (nextLine.Substring(0, 2) != "01") 

到:

while(nextLine != null && nextLine.Substring(0, 2) != "01") 

由于nextLine = SR.ReadLine();是之前的子串,你必须核查空。

享受。

相关问题