0

the text file like this:

id,name,username,password
1,x,js,111
2,y,mm,222

i can read from file and put it on datagridview and this is the code

    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();
    }
Mario S
  • 11,715
  • 24
  • 39
  • 47
  • 1
    You need explain better. When you select some row in datagridview, you want to put a action button like 'Delete Data' ? – Lucas_Santos May 07 '12 at 19:58
  • ok i put button delete to delete selected row and ask about how to delete the line – user1380544 May 07 '12 at 20:02
  • and about the update i make a text box for each column like (textbox for passowrd and so on) and sure i make update button – user1380544 May 07 '12 at 20:04
  • 1
    You can saw http://stackoverflow.com/questions/668907/how-to-delete-a-line-from-a-text-file-in-c – Lucas_Santos May 07 '12 at 20:09
  • If this is your file, I suggest you use Xml instead of a comma-delimited-list. Then you can search for the ID of the line based on the row of the grid easily. – Chuck Savage May 07 '12 at 21:09

1 Answers1

0

you can use regex pattern matching to read it

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

this link may also be helpful

Community
  • 1
  • 1
Zare Ahmer
  • 808
  • 5
  • 8