Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9154461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:25:56+00:00 2026-06-17T12:25:56+00:00

I am trying to do a simple search program that allows the user to

  • 0

I am trying to do a simple search program that allows the user to search for an employee’s name and click on the search button which will return the employee details.

In my Form I have:

    private void buttonSearch_Click(object sender, EventArgs e)
    {
        //set datasource
        dataGridView1.DataSource = controller_emp.search_employee(textBoxSearch.Text);
    }

Controller_Employee:

    public Model_Employee search_employee(string criteria)
    {
        return db.search_employee(criteria);
    }

Model_DB_Employee:

    public Model_Employee search_employee(string criteria)
    {

        Model_Employee result = new Model_Employee();
        for (int i = 0; i < rows.Count; i++)
        {
            if ((string)empTab.Rows[i]["emp_fname"] == criteria)
            {
                result.setId(empTab.Rows[i]["emp_id"].ToString());
                result.setFname(empTab.Rows[i]["emp_fname"].ToString());
                result.setLname(empTab.Rows[i]["emp_lname"].ToString());
                result.setUsername(empTab.Rows[i]["username"].ToString());
                result.setPassword(empTab.Rows[i]["passwd"].ToString());
                result.setJobrole(empTab.Rows[i]["job_role"].ToString());
                result.setContact(empTab.Rows[i]["contact"].ToString());
                result.setEmail(empTab.Rows[i]["email"].ToString());
            }

        }
        return result;

    }

Is there anything wrong with the for loop? It keeps on looping even when the criteria has been met.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:25:57+00:00Added an answer on June 17, 2026 at 12:25 pm

    Use break;

    for (int i = 0; i < rows.Count; i++)
    {
        if ((string)empTab.Rows[i]["emp_fname"] == criteria)
        {
            //result stuff
            break;
        }
    }
    return result;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to program a simple search in google via C# that would run
Afternoon, I am trying to make a simple search, which is working for the
I was trying to implement a simple A* search program based on Wikipedia's pseudocode.
I'm trying to build a search engine that will check a list and then
I am trying to write a simple program using Lucene 2.9.4 which searches for
I was just trying to write a simple binary search tree program where the
Im trying to write a simple sample program which checks for any new mail
im trying to make a simple search on my database from the index action
I'm trying to create a simple search field, what it does is it searches
I'm trying to create a simple search page, but I'm not 100% sure how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.