Answer the question
In order to leave comments, you need to log in
Avoid duplicate foreach loop?
When searching in the MS SQL database for the necessary groups (by condition), it gives duplicates. That is, if 3 groups are found, then they all have the same name. It turns out that he runs through all three, and writes down the first one. Why and how to get around?
foreach (Groups gr in context.Groups.Where(g => g.НазвСпец.Equals(specBox.Text) && g.НомерПрепод.Equals(nameNumber.Text)))
{
groupBox.Items.Add(gr.Группа);
}
Answer the question
In order to leave comments, you need to log in
1. Don't forget to materialize the query using .ToArray()
2. If you already have wildly named columns in the database, call them at least in the code normally
Group, not Groups. ????, not NazvSpec. ???, not Teacher Number.
He should record all three, but, apparently, groupBox prohibits duplicates - then you can add something unique to the group name. (Although groups should have unique names anyway, kmk)
Well, you don’t need to access winform controls from the request yet - copy the texts in advance.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question