2010-03-22 93 views
0

我在Oracle數據庫表(大約400萬條記錄)中有一些數據,我想要使用ADO.NET將其轉換並存儲在MSSQL數據庫中。到目前爲止,我使用了一個DataAdapter來讀取Oracle DataBase中的數據,並將DataTable添加到DataSet中以供進一步處理。如何使用DataReader讀取數據庫記錄並將其添加到DataTable中

當我用我的巨大表格試過這個時,出現了一個outofmemory異常。 (我想這是因爲我無法將整個表加載到我的內存中):)

現在我正在尋找一種很好的方式來執行此提取/傳輸/加載,而不將整個表存儲在內存中。我想使用DataReader並讀取DataTable中的單個dataRecords。如果其中有大約10萬行,我想處理它們並在之後清除DataTable(再次釋放可用內存)。

現在我想知道如何單datarecord作爲行添加到DataTable與ado.net以及如何完全地明確DataTable中出的內存:到目前爲止我的代碼:

Dim dt As New DataTable 

    Dim count As Int32 
    count = 0 
    ' reads data records from oracle database table' 
    While rdr.Read() 

     'read n records and add them to a dataTable' 
     While count < 10000 
      dt.Rows.Add(????) 

      count = count + 1 
     End While 

     'transform data in the dataTable, and insert it to the destination' 


     ' flush the dataTable after insertion' 
     count = 0 
    End While 

謝謝你非常感謝你的迴應!

+0

見http://stackoverflow.com/questions/10844358/read-from-database-and-fill-datatable – nawfal 2013-02-11 07:01:42

回答

1

您可以使用您的原始方法,但在select語句中使用limitskip分批進行。因此,您只需一次執行100,000行並循環,直到獲得所有數據。

你不會有這樣更改代碼太多

+0

謝謝。你能提供一個鏈接或代碼示例來向我展示如何做到這一點? – Olga 2010-03-22 15:14:30

相關問題