Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将c程序结果写入csv文件_C#_Csv - Fatal编程技术网

C# 将c程序结果写入csv文件

C# 将c程序结果写入csv文件,c#,csv,C#,Csv,我有一个c程序,它比较了两个数据库表,并将结果上传到数据库中的另一个表中。我开始出现maxpackets错误。据我所知,上传的结果太大了 我的想法是将结果转储到csv文件。我尝试过几个例子,但我的程序现在只是停顿。我怎么了 { string filePath = @"C:\users\rena\documents\test.csv"; string delimiter = ","; string[]

我有一个c程序,它比较了两个数据库表,并将结果上传到数据库中的另一个表中。我开始出现maxpackets错误。据我所知,上传的结果太大了

我的想法是将结果转储到csv文件。我尝试过几个例子,但我的程序现在只是停顿。我怎么了

{
                string filePath = @"C:\users\rena\documents\test.csv";
                string delimiter = ",";

                string[][] output = new string[][]
                {
                    new string[] { "col 1 row 1", "col 2 row 1", "col 3 row 1"},
                    new string[] {"col 1 row 2", "col 2 row 2", "col 3 row 2"}
                };
                int length = output.GetLength(0);
                StringBuilder sb = new StringBuilder();
                for (int index = 0; index < length; index++)
                    sb.AppendLine(string.Join(delimiter, output[index]));

                if (!File.Exists(filePath))

                File.WriteAllText (filePath, sb.ToString())

            }

谢谢

您可以尝试使用缓冲流进行写入。看看这是否更清楚:

void Main()
{

    string filePath = @"c:\temp\test.csv";
    string delimiter = ",";

    string[][] output = new string[][]
    {
        new string[] { "col 1 row 1", "col 2 row 1", "col 3 row 1"},
        new string[] {"col 1 row 2", "col 2 row 2", "col 3 row 2"}
        //tried with 2k here
    };
    int length = output.GetLength(0);
    StringBuilder sb = new StringBuilder();


    using (FileStream fileStream = File.Create(filePath))
    {
        using (BufferedStream bufferedStream = new BufferedStream(fileStream))
        {
            using (StreamWriter streamWriter = new StreamWriter(bufferedStream))
            {
                for (int index = 0; index < length; index++)
                    streamWriter.WriteLine(string.Join(delimiter, output[index]));
            }   
        }
    }

    if (!File.Exists(filePath))

    File.WriteAllText (filePath, sb.ToString());

}

用户名在商业网站上做广告。垃圾邮件?-看起来不是这样:这个示例是否也会停滞?或者这只是一个最小版本的什么摊位?你能做一个最小的版本来暂停吗?你的代码看起来不错,发生了什么错误?这听起来像是一个错误。为什么不能“将结果上传到另一个表”?你得到一个“maxpackets错误”?向我们展示错误并解决它;摆弄CSV文件可能会让你误入歧途。