像这样的文本文件:
id,name,username,password
1,x,js,111
2,y,mm,222
我可以从文件中读取并将其放在 datagridview 上,这是代码
private void buttonTadd_Click(object sender, EventArgs e)
{
FileStream fs = new FileStream(@"C:\Users\HP\Documents\Visual Studio 2008\Projects\BankServer\TellerFile.txt", FileMode.Append);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(textBoxTNumber.Text +","+ textBoxTName.Text +","+ textBoxTUserName.Text +","+ textBoxTPassword.Text);
sw.Close();
dataGridViewTellers.Rows.Clear();
StreamReader sr = new StreamReader(@"C:\Users\HP\Documents\Visual Studio 2008\Projects\BankServer\TellerFile.txt");
string line;
while ((line = sr.ReadLine()) != null)
{
dataGridViewTellers.Rows.Add(line.Split(','));
}
sr.Close();
}