mrpddnos
Freshman
Hi everyone,
I'm trying to set up a piece of code that does the following. In a RichTextBox I add a series of numbers (each number on a different line). Then I press the add butting a foreach loop reads the first line and starts a new forach loop. this new loop sees wether the number is allready in the dataset. If so, a error is shown. If not, the loop continues and the number is added to the dataset. Then it starts over again with the next number, and so on. The propblem is, when I start debugging I get the messagebox stating that the loop was succesfull everytime, though no numbers are added to the dataset.
Here is the code:
The code used to work when I did not had the program check if the number exist yet. What did I do wrong?
yours,
bernhard
I'm trying to set up a piece of code that does the following. In a RichTextBox I add a series of numbers (each number on a different line). Then I press the add butting a foreach loop reads the first line and starts a new forach loop. this new loop sees wether the number is allready in the dataset. If so, a error is shown. If not, the loop continues and the number is added to the dataset. Then it starts over again with the next number, and so on. The propblem is, when I start debugging I get the messagebox stating that the loop was succesfull everytime, though no numbers are added to the dataset.
Here is the code:
Code:
private void btnNropslaan_Click(object sender, EventArgs e)
{
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"]);
lbroepnrnieuwbericht1.Items.Add(drRoepnr[0]);
}
else
{
MessageBox.Show("Een van de roepnummers bestaat al", "Error");
}
}
}
MessageBox.Show("Roepnummer is toegevoegd!", "Toegevoegd!");
}
The code used to work when I did not had the program check if the number exist yet. What did I do wrong?
yours,
bernhard