I have a problem with if function. I have 3 string arrays ("orderID", "id" and "name")
- orderID contains maximum 10 order numbers.
- id and name are database which contains almost every drink.
I want if "orderID" matches to "id", "name" to be added to the list, if not then string "Not found in database" to be added.
Current code :
string x = "Not found in database";
for (int i = 0; i < id.Length; i++)
{
foreach (string ids in orderID)
{
if (ids == id[i])
{
listBox1.Items.Add(name[i]);
listBox2.Items.Add(name[i]);
break;
}
else
{
listBox2.Items.Add(x);
}
}
}
Problems: (visible on link placed above : "Here is the result")
- 2nd List - when "orderID" matches to the "id", "name" is added to the list, but not at desired position. I guess it's adding by position in database. How to avoid that?
- 3rd List is just duplicate with "else" added. Else it's not working as expected.It's adding "Not found in database" for everything. Any suggestion how to fix it?
Aucun commentaire:
Enregistrer un commentaire