Click here to Skip to main content
15,891,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have 1 M rows and 140 columns in a datatable . I would like to create CSV of these datas. I have done this but it takes 50 minutes to create CSV data. Could you let me know how to optimism large CSV writer.


Framework 3.5
Database :- oracle 10 G
Entity Framework 3.5


Regards,
Rajesh
Posted
Comments
[no name] 14-Dec-11 23:29pm    
You can't export the data directly from Oracle? You can with SQL Server.
Jörgen Andersson 19-Dec-11 1:44am    
Why not?
Or what is your definition if direct?
[no name] 19-Dec-11 6:36am    
It was a question, not a statment.
Jörgen Andersson 19-Dec-11 7:12am    
Oh, sorry, my bad.

Once you fetch the table data from the Oracle database, you can export the it similar way which is shown in the sample link.How to export data to CSV file in ASP.NET[^]

NOTE: In order to fetch the exportable data, you may need to use Oracle data provider(ODP)[^] to .Net Framework. Here is sample link Building a .NET Application on Oracle Database[^]
 
Share this answer
 
you can try this. if this work better then use of it.

private  string ExportToCSV(DataTable DataTable, string path)
    {
        string fullpath = "";
        fullpath = path;
        StreamWriter SW;
        SW = File.CreateText(fullpath);
        System.Text.StringBuilder oStringBuilder = new System.Text.StringBuilder();
        foreach (DataColumn oDataColumn in DataTable.Columns)
        {
            oStringBuilder.Append(oDataColumn.ColumnName + ",");
        }
        SW.WriteLine(oStringBuilder.ToString().Substring(0, oStringBuilder.ToString().Length - 1));
        oStringBuilder.Length = 0;
        foreach (DataRow oDataRow in DataTable.Rows)
        {
            foreach (DataColumn oDataColumn in DataTable.Columns)
            {
                oStringBuilder.Append(oDataRow[oDataColumn.ColumnName] + ",");
            }
            SW.WriteLine(oStringBuilder.ToString().Substring(0, oStringBuilder.ToString().Length - 1));
            oStringBuilder.Length = 0;
        }
        SW.Close();
        return fullpath;
    }
 
Share this answer
 
Here's[^] a link to a couple of solutions from Tom Kyte.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900