C#中的大型CSV文件创建器 [英] Large CSV File creator in C#

查看:145
本文介绍了C#中的大型CSV文件创建器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在数据表中有100万行和140列.我想为这些数据创建CSV.我已经做到了,但是创建CSV数据需要50分钟.您能否让我知道如何乐观大型CSV编写器.


框架3.5
数据库:-oracle 10 G
实体框架3.5


问候,
Rajesh

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

推荐答案

从Oracle数据库中获取表数据后,您可以按照示例链接中所示的类似方式导出它. ^ ]

注意:为了获取可导出的数据,您可能需要使用 Oracle数据提供程序(ODP) [ ^ ]转换为.Net Framework.这是示例链接在Oracle数据库上构建.NET应用程序 [
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[^]


,您可以尝试一下.如果效果更好,请使用它.

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


此处 [ ^ ]指向Tom Kyte的一些解决方案的链接.
Here''s[^] a link to a couple of solutions from Tom Kyte.


这篇关于C#中的大型CSV文件创建器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆