【发布时间】:2016-12-21 02:08:57
【问题描述】:
我在我的代码中遇到了一些问题,当它读取 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);
}
}
【问题讨论】: