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

  • SEARCH
  • Home
  • 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 6201807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:37:18+00:00 2026-05-24T04:37:18+00:00

I’m creating an application in Visual Studio 2010 C# and MySQL where the user

  • 0

I’m creating an application in Visual Studio 2010 C# and MySQL where the user can add, edit, view an employee. I already done with adding and viewing part. However I’m little confused in editing. I have this listView in my form where it displays all the employee added to the database. What I want is that whenever the user will select an employee and click edit button I want the values saved in the database to show in the corresponding textboxes below the listView. Can someone give me any idea how to do this? Please

Screenshot:
enter image description here

Code for listView:

private void getEmployee()
    {
        listViewEmployee.Items.Clear();
        string cmd = "select employee_number, employee_lastname, employee_firstname, employee_middlename, employee_position, employee_datehired from employee";
        DBConn db = new DBConn();
        DataTable tbl = db.retrieveRecord(cmd);
        foreach (DataRow row in tbl.Rows)
        {
            ListViewItem lv = new ListViewItem(row[0].ToString());
            lv.SubItems.Add(row[1].ToString() + ", " + row[2].ToString() + " " + row[3].ToString());
            lv.SubItems.Add(row[4].ToString());
            lv.SubItems.Add(row[5].ToString());
            listViewEmployee.Items.Add(lv);
        }
    }

    private void textBoxSearchEmployee_TextChanged(object sender, EventArgs e)
    {
        string cmd = "SELECT employee_number, employee_lastname, employee_firstname, employee_middlename, employee_position, employee_datehired FROM employee where employee_lastname Like '" + textBoxSearchEmployee.Text + "%'";
        listViewEmployee.Items.Clear();
        DBConn db = new DBConn();
        DataTable tbl = db.retrieveRecord(cmd);
        foreach (DataRow row in tbl.Rows)
        {
            ListViewItem lv = new ListViewItem(row[0].ToString());
            lv.SubItems.Add(row[1].ToString() + ", " + row[2].ToString() + " " + row[3].ToString());
            lv.SubItems.Add(row[4].ToString());
            lv.SubItems.Add(row[5].ToString());
            listViewEmployee.Items.Add(lv);
        }
    }
  • 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-05-24T04:37:18+00:00Added an answer on May 24, 2026 at 4:37 am

    It seems to me you are able to populate the listView only.

    A few pointers:

    1) The way you’re writing your SQL statement now is prone to SQL Injection. Use parameters in your SQL commands instead of directly concatenating the variables to your query. See this question for an example on how to do it.

    2) Depending on where your other relevant data is located (i.e. if your database is normalized), you might have to do a join in your query.

    string sqlQuery = "SELECT * FROM employee 
    JOIN other_employee_data_table on other_employee_data_table.employeeID = employee.ID
    WHERE employee.employee_lastname LIKE @employee_lastname +'%'"
    

    But if your employee table contains all the data, then no need to do a join. Just get all the relevant information from that table.

    3) Once you got all the information you need, it’s just a matter of reading those data and assigning them to their respective fields.

    Pseudo Code:

    using (MySqlConnection connection = new MySqlConnection(connectionString))
    {
       connection.Open(); 
       MySqlCommand command = connection.CreateCommand();
       command.CommandText = sqlQuery;
       command.CommandType = System.Data.CommandType.Text;
       // add parameters in this line
       using (MySqlDataReader reader = command.ExecuteReader())
       {  
          while (reader.Read()) 
          {     
             // iterate in each row
             for (int i = 0; i < reader.FieldCount; i++)
             {
                // iterate each column using reader.GetValue(i)
             }
          }
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.