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 7447825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:53:28+00:00 2026-05-29T12:53:28+00:00

I developed a web-based training matrix that shows the training record for each employee

  • 0

I developed a web-based training matrix that shows the training record for each employee in each division in my department in the company. Everything works well except one thing; when the Admin updates the training record for some employees and he clicks on the Update button, he will see his latest updates immediately, but after a period of time when he updates the matrix again, he will not see his previous entered data. They will be disappeared and I don’t know why. I checked the database and there was no data, too and there is no body touched the database. It is really strange.

I developed the Updating functionality to be like (delete and insert) instead of using Update. I think the problem now is with the deleting functionality. I need to modify it in such a way to be specific for a determined employee not for everyone as displayed below, so how to do that?

Code-Behind (C# code):

protected void Page_Load(object sender, EventArgs e)
{

    DataView dv2 = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
    foreach (DataRowView group in dv2)
    {
        SqlDataSource2.SelectParameters[0].DefaultValue = group[0].ToString();
        //create a new HtmlTable object
        HtmlTable table = new HtmlTable();

        DataView dv = (DataView)SqlDataSource2.Select(DataSourceSelectArguments.Empty);
        int columns = dv.Table.Columns.Count;
        int rows = dv.Count;

        //table's formating-related properties
        table.Border = 2;
        table.CellPadding = 3;
        table.CellSpacing = 3;
        table.Width = "900px";

        //to get the css style
        table.Attributes["class"] = "uGrid";

        //create a new HtmlTableRow and HtmlTableCell objects
        HtmlTableRow row;
        HtmlTableRow header = new HtmlTableRow();
        HtmlTableCell cell;


        //for adding the headers to the table
        foreach (DataColumn column in dv.Table.Columns)
        {
            HtmlTableCell headerCell = new HtmlTableCell("th");
            headerCell.InnerText = column.Caption;
            header.Cells.Add(headerCell);
        }
        table.Rows.Add(header);

        //loop for adding rows to the table
        foreach (DataRowView datarow in dv)
        {
            row = new HtmlTableRow();
            //row.BgColor = "yellow";


            //loop for adding cells
            for (int j = 0; j < columns; j++)
            {
                cell = new HtmlTableCell();
                if (j < 4)
                {
                    cell.InnerText = datarow[j].ToString();
                }
                else
                {

                    CheckBox checkbox = new CheckBox();

                    int checkBoxColumns = dv.Table.Columns.Count - 5;
                    string fieldvalue = datarow[j].ToString();
                    string yes = fieldvalue.Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries)[1];
                    string courseid = fieldvalue.Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries)[0];
                    checkbox.ID = row.Cells[3].InnerText + "," + courseid.Trim();
                    checkbox.Checked = yes.Equals("Yes");
                    cell.Controls.Add(checkbox);

                }

                //add the cell to the current row
                row.Cells.Add(cell);
            }

            //add the row to the table
            table.Rows.Add(row);
        }

        //add the table to the page
        PlaceHolder1.Controls.Add(table);

    }
}


protected void updateButton_Click(object sender, EventArgs e)
{
    string connString = "Data Source=localhost\\sqlexpress;Initial Catalog=psspTest;Integrated Security=True";
    string deleteCommand = "DELETE FROM employee_courses where employeeID=@employeeID";
    string insertCommand = "INSERT INTO employee_courses (employeeId, CourseID) values(@employeeId, @CourseID)";

    using (SqlConnection conn = new SqlConnection(connString))
    {
        conn.Open();
        using (SqlCommand cmd = new SqlCommand(deleteCommand, conn))
        {
            cmd.ExecuteNonQuery();
        }
    }

    foreach (Control ctrl in PlaceHolder1.Controls)
    {
        if (ctrl is HtmlTable)
        {
            HtmlTable table = (HtmlTable)ctrl;
            foreach (HtmlTableRow row in table.Rows)
            {
                foreach (HtmlTableCell cell in row.Cells)
                {
                    foreach (Control c in cell.Controls)
                    {
                        if (c is CheckBox)
                        {
                            CheckBox checkbox = (CheckBox)c;
                            if (checkbox.Checked)
                            {
                                string fieldvalue = checkbox.ID;
                                string employeeID = fieldvalue.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)[0];
                                string courseID = fieldvalue.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)[1];

                                using (SqlConnection conn = new SqlConnection(connString))
                                {
                                    conn.Open();
                                    using (SqlCommand cmd = new SqlCommand(insertCommand, conn))
                                    {
                                        //Now the insert
                                        cmd.CommandText = insertCommand;
                                        cmd.Parameters.Clear(); //need this because still has params from del comm
                                        cmd.Parameters.AddWithValue("@employeeId", employeeID);
                                        cmd.Parameters.AddWithValue("@CourseID", courseID);
                                        cmd.ExecuteNonQuery();
                                    }
                                }

                            }

                        }
                    }
                }
            }

        }

    }

    Response.Redirect("KPIReport.aspx");
}

The problem is here:

protected void updateButton_Click(object sender, EventArgs e)
    {
        string connString = "Data Source=localhost\\sqlexpress;Initial Catalog=psspTest;Integrated Security=True";
        string deleteCommand = "DELETE FROM employee_courses where employeeID=@employeeID";
        string insertCommand = "INSERT INTO employee_courses (employeeId, CourseID) values(@employeeId, @CourseID)";

        using (SqlConnection conn = new SqlConnection(connString))
        {
            conn.Open();
            using (SqlCommand cmd = new SqlCommand(deleteCommand, conn))
            {
                cmd.ExecuteNonQuery();
            }
        }

        foreach (Control ctrl in PlaceHolder1.Controls)
        {
            if (ctrl is HtmlTable)
            {
                HtmlTable table = (HtmlTable)ctrl;
                foreach (HtmlTableRow row in table.Rows)
                {
                    foreach (HtmlTableCell cell in row.Cells)
                    {
                        foreach (Control c in cell.Controls)
                        {
                            if (c is CheckBox)
                            {
                                CheckBox checkbox = (CheckBox)c;
                                if (checkbox.Checked)
                                {
                                    string fieldvalue = checkbox.ID;
                                    string employeeID = fieldvalue.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)[0];
                                    string courseID = fieldvalue.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)[1];

                                    using (SqlConnection conn = new SqlConnection(connString))
                                    {
                                        conn.Open();
                                        using (SqlCommand cmd = new SqlCommand(insertCommand, conn))
                                        {
                                            //Now the insert
                                            cmd.CommandText = insertCommand;
                                            cmd.Parameters.Clear(); //need this because still has params from del comm
                                            cmd.Parameters.AddWithValue("@employeeId", employeeID);
                                            cmd.Parameters.AddWithValue("@CourseID", courseID);
                                            cmd.ExecuteNonQuery();
                                        }
                                    }

                                }

                            }
                        }
                    }
                }

            }

        }

        Response.Redirect("KPIReport.aspx");
  • 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-29T12:53:41+00:00Added an answer on May 29, 2026 at 12:53 pm

    Seems you are not setting @EmployeeID for delete command as in following lines:

    protected void updateButton_Click(object sender, EventArgs e)
    {
        //COMMAND DEFINED
        string deleteCommand = "DELETE FROM employee_courses where employeeID=@employeeID";
    
        using (SqlConnection conn = new SqlConnection(connString))
        {
            conn.Open();
    
            //COMMAND CREATED
            using (SqlCommand cmd = new SqlCommand(deleteCommand, conn))
            {
                //COMMAND EXECUTED, BUT @employeeID NOT SET ANYWHERE
                cmd.ExecuteNonQuery();
            }
        }
    

    try following:

    //TO KEEP TRACK OF EMPLOYEE IDS FOR WHICH WE HAVE ALREADY EXECUTED 
    //DELETE STATEMENT
    IList<string> _deleted=new List<string>();
    
    foreach (Control ctrl in PlaceHolder1.Controls)
    {
        ...........
        .........
    
        if (c is CheckBox)
        {
            CheckBox checkbox = (CheckBox)c;
            if (checkbox.Checked)
            {
                string fieldvalue = checkbox.ID;
                string employeeID = fieldvalue.Split(new string[] { "," }, 
                                       StringSplitOptions.RemoveEmptyEntries)[0];
                string courseID = fieldvalue.Split(new string[] { "," }, 
                                       StringSplitOptions.RemoveEmptyEntries)[1];
    
                if(!_deleted.Contains(employeeID))
                {
                    using (SqlConnection conn = new SqlConnection(connString))
                    {
                       conn.Open();
                       using (SqlCommand cmd = new SqlCommand(deleteCommand, conn))
                       {
                          cmd.Pararmeters.AddWithValue("@employeeId", employeeID);
                          cmd.ExecuteNonQuery();
                          //DON'T EXECUTE DELETE FOR ALL CHECKED ROWS
                          _deleted.Add(employeeID);
                       }
                    }
                }
    
                using (SqlConnection conn = new SqlConnection(connString))
                {
                    conn.Open();
                    using (SqlCommand cmd = new SqlCommand(insertCommand, conn))
                    {
                       //Now the insert
                       cmd.CommandText = insertCommand;
                       //DON'T NEED TO CLEAR AS YOU HAVE CREATED NEW COMMAND IN 
                       //USING STATEMENT
                       //cmd.Parameters.Clear();
                        cmd.Parameters.AddWithValue("@employeeId", employeeID);
                        Cmd.Parameters.AddWithValue("@CourseID", courseID);
                        cmd.ExecuteNonQuery();
                    }
                }
            }
            .....................
            .....................
        }
        .....................
        .....................
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an in house developed web-based admin console that uses a combination of
The following databases exist for each internally and independently developed software (web-based or client-server)
I'm working on a web based application that belongs to an automobil manufacturer, developed
I'm working on a web based application that belongs to an automobil manufacturer, developed
My boss have given me assignment to find how a web based application developed
For a little background, I work for a firm that develops web-based enterprise social
I've never developed a web application that uses distributed memory. Is it common practice
I've developed a web application that worked fine in JBoss 4. Now, I need
I've developed a web-based mobile application using Jquery Mobile and HTML5. Now, can I
I've developed a web based point of sale system for one of my clients

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.