如何从datagridview中选择行从文本文件中删除和更新信息?

时间:2012-05-07 19:50:15

标签: c#

这样的文本文件:

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();
    }

1 个答案:

答案 0 :(得分:0)

你可以使用正则表达式模式匹配来阅读它

File.WriteAllText("Path", Regex.Replace(File.ReadAllText("Path"), "[Pattern]", "Replacement"));

link也可能有所帮助