read RichTextBox line by line (C#)

With my .DOT teacher I looked at the code and he gave me the next advise:

I sould write a code that checks wether or not dslogging.Tables["roepnummers"] is empty. If the table is empty, then the numers should just be entered. If it's not empty then each number should be checked to see if the numer allready exists. This is what I did:

Code:
private void btnNropslaan_Click(object sender, EventArgs e)
        {
            if (dsLogging.Tables["roepnummers"].Rows.Count == 0)
            {
                foreach (string nummer in rtbRoepnummers.Lines)
                {                
                    DataRow drRoepnr = dsLogging.Tables["roepnummers"].NewRow();
                    drRoepnr["nummer"] += nummer;
                    dsLogging.Tables["roepnummers"].Rows.Add(drRoepnr["nummer"]);
                    lbroepnrnieuwbericht2.Items.Add(drRoepnr[0]);
                    ClbRoepnr.Items.Add(drRoepnr[0]);
                }
            }
            else
            {
                foreach (string nummer in rtbRoepnummers.Lines)
                {
                    foreach (DataRow drRoepnrc in dsLogging.Tables["roepnummers"].Rows)
                    {
                        if (drRoepnrc["nummer"].ToString() != nummer)
                        {
                            DataRow drRoepnr = dsLogging.Tables["roepnummers"].NewRow();
                            drRoepnr["nummer"] += nummer;
                            dsLogging.Tables["roepnummers"].Rows.Add(drRoepnr["nummer"]);
                            lbroepnrnieuwbericht2.Items.Add(drRoepnr[0]);
                            ClbRoepnr.Items.Add(drRoepnr[0]);
                        }
                        break;
                    }
                }
            }
                MessageBox.Show("Roepnummer is toegevoegd!", "Toegevoegd!");
        }

What I now get is the folowing. When I add some numbers everything works fine. When I update the number list with new numbers the variable "nummer" stays "1" though it should be increased each time.

Code:
[B]Example:[/B]
A list of numbers in the dataset...
1
2

In the RichTextBox the folowing numbers are shown:
1
2

I update the list to this:
1
2
3
4
5

The result in the dataset will be:
1
2
2
3
4
5

I add the folowing numbers:
6
7

Result:
1
2
2
3
4
5
2
3
4
5
6
7

As you can see only the FIRST number will be used to check if it allready exist. It should check every number in the dataset. How can I get this done?


The reason why I started with this is because according to my teacher I am trying to use data from an empty datatable. And that can't be done. And that sounds right since the program starts to work now that I have the software checking the table wether or not it is empty.
 
Back
Top