Click here to Skip to main content
12,882,639 members (34,061 online)

how to Check if already exists a employer in the list with same code entered in textbox

mibetty asked:

Open original thread

I need your help, if it is possibe.

I need to check if already exists a employer in the list with same code entered in the textbox.

I have a list of employers, and I add employers like this :
else if (cb_type.Text == type1.text)
     type1 typeone = new typeone(Convert.ToInt32(tb_Code.Text), tb_Name.Text, Convert.ToDateTime(dateTimePicker1.Text), cb_Sex.Text, tb_Adress.Text, Convert.ToInt32(tb_Phone.Text), tb_Email.Text, pictureBox1.Image);

In the moment that i add a new employer i need to verify if already exists a employer with the same code that is entered in textbox.

I try this :
foreach (employer E in Lemployer)
      if tb_code.text == E.getCode())
 "Code Already exists");

But this isn't working, someone can help me doing this?

Tags: C#


When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).

Advertise | Privacy | Mobile
Web02 | 2.8.170422.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100