我有一部分程序,当用户A登录时,A有能力编辑名称和密码等个人资料。配置文件数据将显示在数据网格上(文件txt中的源)。
但我不知道为什么数据不会显示,这是我的文本文件:( col:name,employee ID,password)
admin#EMP001#iamadmin#
staff#EMP002#iamstaff#
这是我的代码,它基于EmployeeID获取数据。
public void viewDataProfil()
{
string line, search;
string[] strArray = new string[3];
Boolean find = false;
dataGridView1.Rows.Clear();
dataGridView1.ColumnCount = 3;
dataGridView1.Columns[0].Name = "User Name";
dataGridView1.Columns[1].Name = "EmployeeID";
dataGridView1.Columns[2].Name = "Password";
F = new FileStream("Login.txt", FileMode.Open, FileAccess.Read);
R = new StreamReader(F);
search = lblEmployeeID.Text; //in lblEmployeeID.Text, i'm using another method that getting data form file txt also
while ((line = R.ReadLine()) != null)
{
int stringStartPos = line.IndexOf('#');
if (search.Equals(line.Substring(0, stringStartPos)))
{
find = true;
strArray = line.Split(new string[] { "#" }, StringSplitOptions.None);
txtUserName.Text = strArray[0];
lblEmployeeID.Text = strArray[1];
txtPassword.Text = strArray[2];
dataGridView1[0, 0].Value = strArray[0];
dataGridView1[1, 0].Value = strArray[1];
dataGridView1[2, 0].Value = strArray[2];
}
}
if (!find)
{
MessageBox.Show("Sorry data not found!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
R.Close();
F.Close();
}