本文介绍了SDF文件转换为CSV文件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我正在尝试制作一个可以将SDF文件传输到CSV文件的转换器。但我不知道为什么它不起作用..你在这里看到的部分我几乎已经离开互联网..



Hey i am trying to make a converter which can transfer a SDF File into a CSV File. But i don't know why it isn't working.. The section which ya can see here I almost got out of the internet..

private void button2_Click(object sender, EventArgs e)
        {

            SqlCeConnection conn = null;
            SqlCeCommand cmd = null;
            SqlCeDataReader rdr = null;

            try
            {
                System.IO.TextWriter stm = new System.IO.StreamWriter(new System.IO.FileStream(@"D:\\TEST\Data.csv", System.IO.FileMode.Create), Encoding.Default);
                while ()
                {

                    for (int i = 0; i < rdr.FieldCount - 2; i++)
                    {
                        if (rdr[i] != null)
                        {
                            stm.Write(rdr[i].ToString());
                            stm.Write(";");
                        }
                        else
                        {
                            stm.Write(";");
                        }
                    }
                    if (rdr[rdr.FieldCount - 1] != null)
                    {
                        stm.Write(rdr[0].ToString());
                    }
                    stm.Write(System.Environment.NewLine);
                }
                stm.Close();
                rdr.Close();
                cmd.Dispose();
            }
            finally
            {
                conn.Close();
            }
        }





我的尝试:



没什么,我在互联网上抬头但找不到任何东西......



What I have tried:

Nothing, i looked up in the internet but couldn't find anything...

推荐答案

SqlCeDataReader rdr = null;

try
{
    System.IO.TextWriter stm = new System.IO.StreamWriter(new System.IO.FileStream(@"D:\\TEST\Data.csv", System.IO.FileMode.Create), Encoding.Default);
    while ()
    {

        for (int i = 0; i < rdr.FieldCount - 2; i++)

until你这样做,总是会失败并带有空引用异常。



和顺便说一句:在互联网上寻找代码并试图在不知道你是什么的情况下使用它做不是试图转换器 - 它希望并祈祷奇迹发生。它不会。即使您发现工作代码完全按照您在其他人的程序中完成的工作,您需要了解代码及其工作原理,然后将其更改为在您的工作中完成该工作...

Until you do, that will always fail with a null reference exception.

And BTW: looking for code on the internet and trying to use it without knowing anything about what you are doing is not "trying to make a converter" - it's hoping and praying for a miracle to occur. It won't. Even if you find working code that does exactly the job you need it to in someone else's program, you need to understand the code and how it works, and then change it to do that job in yours...



这篇关于SDF文件转换为CSV文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 21:57
查看更多