csv阅读重复

时间:2016-08-14 18:41:38

标签: c# csv converter

enter image description here

我在我的代码中遇到了一些问题,当它读取SQL文件时,它会复制条目,有时会将它们按错误的顺序排列。我一直在单步执行代码并检查值,但我找不到任何内容,应该只有4个条目。

    private void LoadBtn_Click(object sender, EventArgs e)
    {
        //Opens a browse box to allow the user to select which file, only CSV's allow allowed
        OpenFileDialog openFileDialog1 = new OpenFileDialog();
        openFileDialog1.Filter = "CSV Files (*.csv)|*.csv";
        openFileDialog1.FilterIndex = 1;

        //empties text box when clicked | loads file location and name to load directory text box at top
        if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            ConvertedText.Text = string.Empty;
            LoadDirectory.Text = openFileDialog1.FileName.ToString();
        }
        string filename = LoadDirectory.Text;
        string[] Lines = File.ReadAllLines(filename);
        string[] Fields;
        string outfile = "";

        for (int i = 1; i < Lines.Length; i++)
        {
            Fields = Lines[i].Split(new char[] { ',' });
            outfile += "IF EXISITS (SELECT USERID FROM WUSERS WHERE USERID='" + Fields[0] + "')" + Environment.NewLine;
            outfile += "begin" + Environment.NewLine;
            ConvertedText.AppendText(outfile);
        }
        }

0 个答案:

没有答案