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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:38:35+00:00 2026-05-23T01:38:35+00:00

The method below that updates the database is called UpdateHold(). This instance of the

  • 0

The method below that updates the database is called UpdateHold(). This instance of the object uses the second constructor. I ran debug to verify that the hold object “thisHold” is updating the values that are being changed in the form. But when I view the values of the db object after the submit happens, I see it is unchanged, same in the physical database. Why isn’t this updating?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Data.Linq;
using System.Text;
using System.Windows.Forms;

namespace Coke_Hold_Database
{
    public partial class frmFGHold : Form
    {
        private PINAuthentication cert = new PINAuthentication();
        linqCokeDBDataContext db = new linqCokeDBDataContext();
        Record_HoldData thisHold;
        bool isNew; //flag if hold is new or not


        public frmFGHold()
        {
            //constructor for new hold
            InitializeComponent();
            populateLists();
            thisHold = new Record_HoldData();

            isNew = true;
            btnEdit.Visible = false;
        }

        public frmFGHold(Record_HoldData holdData)
        {
            //constructor for existing hold (edit)
            InitializeComponent();
            populateLists();
            this.thisHold = holdData;

            //fill out the form
            FillForm();

            isNew = false;
            btnEdit.Visible = true;
        }

        private void FillForm()
        {
            //fill out the form with existing information

            txtPONumber.Text = thisHold.PO_.ToString();
            cboProductionSupervisor.SelectedValue = thisHold.ProductionSupervisor;
            cboLineNumber.SelectedValue = thisHold.LineNumber;
            cboQASupervisor.SelectedValue = thisHold.QASupervisor;
            cboFlavorName.SelectedValue = thisHold.Flavor;
            cboContainer.Text = thisHold.ContainerType;
            cboContainerSize.Text = thisHold.ProductSize;
            cboPackage.Text = thisHold.Package;
            txtQuantity.Text = thisHold.HoldQty.ToString();
            mtbDateCode.Text = thisHold.DateCode;
            cboDefectiveComponent.Text = thisHold.NonConformingItem;
            cboDefectReason.Text = thisHold.NonConformance;
            cboOccuredAt.Text = thisHold.FoundDuring;
            chkTestRequired.Checked = (bool) thisHold.TestRequired;
            txaDescription.Text = thisHold.Comments;
            txaRootCauseAnalysis.Text = thisHold.RootCause;
        }

        private void UpdateHoldObject()
        {
            thisHold.PO_ = int.Parse(txtPONumber.Text);
            thisHold.ProductionSupervisor = (int)cboProductionSupervisor.SelectedValue;
            thisHold.LineNumber = (int) cboLineNumber.SelectedValue;
            thisHold.QASupervisor = (int) cboQASupervisor.SelectedValue;
            thisHold.Flavor = (int) cboFlavorName.SelectedValue;
            thisHold.ContainerType = cboContainer.Text;
            thisHold.ProductSize = cboContainerSize.Text;
            thisHold.Package = cboPackage.Text;
            thisHold.HoldQty = int.Parse(txtQuantity.Text);
            thisHold.DateCode = mtbDateCode.Text;
            thisHold.NonConformingItem = cboDefectiveComponent.Text;
            thisHold.NonConformance = cboDefectReason.Text;
            thisHold.FoundDuring = cboOccuredAt.Text;
            thisHold.TestRequired = chkTestRequired.Checked;
            thisHold.Comments = txaDescription.Text;
            thisHold.RootCause = txaRootCauseAnalysis.Text;
        }

        private void CreateNewHold()
        {
            db.Record_HoldDatas.InsertOnSubmit(thisHold);
            //GenerateHoldNumber()
            db.SubmitChanges();
            MessageBox.Show(this, "Hold submitted!\n\nYou're hold number is " + thisHold.HoldID.ToString(),"Hold #" + thisHold.HoldID.ToString() + " created", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();
        }

        private void UpdateHold()
        {
            db.SubmitChanges();
            MessageBox.Show(this, "Hold #" + thisHold.HoldID.ToString() + " updated.", thisHold.HoldID.ToString() + " updated", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();   
        }

        private bool ValidateEntry()
        {
            //TODO write some frakkin validation
            return true;
        }

        private void GetPIN()
        {
            frmPINPrompt pin = new frmPINPrompt(cert);
            pin.ShowDialog();
        }

        private void SubmitData()
        {
            UpdateHoldObject();
            GetPIN();

            if (ValidateEntry() && cert.authenticated)
            {
                try
                {
                    if (isNew)
                    {
                        thisHold.LabTech = cert.empNumber;
                        thisHold.LastEditBy = cert.empNumber;
                        thisHold.HoldStatus = "Open";
                        thisHold.DateOpened = DateTime.Now;
                        thisHold.LastEditDate = DateTime.Now;

                        CreateNewHold();
                    }
                    else
                    {
                        thisHold.LastEditBy = cert.empNumber;
                        thisHold.LastEditDate = DateTime.Now;

                        UpdateHold();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }

        public void populateLists()
        {
            //load production names
            var productionNames =
                from a in db.LUT_Employees
                where a.position == "Supervisor" && a.department == "Production"
                select new { ID = a.ID, Names = a.lastName + ", " + a.firstName };

            cboProductionSupervisor.DataSource = productionNames;
            cboProductionSupervisor.DisplayMember = "Names";
            cboProductionSupervisor.ValueMember = "ID";

            //load QA names
            var qaNames =
                from a in db.LUT_Employees
                where a.position == "Supervisor" && a.department == "Quality Assurance"
                select new { ID = a.ID, Names = a.lastName + ", " + a.firstName };

            cboQASupervisor.DataSource = qaNames;
            cboQASupervisor.DisplayMember = "Names";
            cboQASupervisor.ValueMember = "ID";

            //load flavor names
            var flavorNames =
                from a in db.LUT_Flavors
                select new { ID = a.ID, Flavor = a.flavor };

            cboFlavorName.DataSource = flavorNames;
            cboFlavorName.DisplayMember = "flavor";
            cboFlavorName.ValueMember = "ID";

            //load line numbers
            var lineNumbers =
                (from a in db.LUT_ProductionLines
                select new { a.lineNumber }).ToList();

            cboLineNumber.DataSource = lineNumbers; 
            cboLineNumber.DisplayMember = "LineNumber";
            cboLineNumber.ValueMember = "LineNumber";
        }

        private void mtbDateCode_MouseUp(object sender, MouseEventArgs e)
        {
            SendKeys.Send("{HOME}");
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure you want to cancel? All data will be lost!", "Confirm Cancel", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);
            if (result == DialogResult.Yes)
            {
                this.Close();
            }
            else { }
        }





        private void btnSubmit_Click(object sender, EventArgs e)
        {
            SubmitData();

        }

        private void linkAutoFill_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            //autogenerage date code
            mtbDateCode.Text = Etc.BuildDateCode(DateTime.Now,(int)cboFlavorName.SelectedValue,cboContainer.Text,Etc.getDayCode(DateTime.Now),int.Parse(cboLineNumber.Text));
        }

        private void cboContainerSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            //load package sizes
            var packageSizes =
                from a in db.LUT_Packagings
                where a.Container == cboContainer.Text && a.Size == cboContainerSize.SelectedValue
                select new { ID = a.ID, Size = a.Package };

            cboPackage.DataSource = packageSizes;
            cboPackage.DisplayMember = "Size";
            cboPackage.ValueMember = "ID";

        }

        private void cboContainer_SelectedIndexChanged(object sender, EventArgs e)
        {
            //make container size list
            var containerSizes =
                from a in db.LUT_Containers
                where a.ContainerType == cboContainer.Text
                select new { ID = a.ID, Size = a.size };

            cboContainerSize.DataSource = containerSizes;
            cboContainerSize.DisplayMember = "Size";
            cboContainerSize.ValueMember = "ID";

            //load components
            var defectiveComponents =
                from a in db.LUT_ContainerComponents
                where a.Container == cboContainer.Text
                select new { ID = a.ID, Comp = a.Component };

            cboDefectiveComponent.DataSource = defectiveComponents;
            cboDefectiveComponent.DisplayMember = "Comp";
            cboDefectiveComponent.ValueMember = "ID";
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            //TODO ask verify PIN
            foreach (Control c in this.Controls)
            {
                c.Enabled = true;
            }

            btnSubmit.Text = "Update Hold";
        }
    }
}
  • 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-23T01:38:36+00:00Added an answer on May 23, 2026 at 1:38 am

    The database is not updated, because you’re submitting changes on the db DataContext, and the ‘hold’ you’ve provided through the constructor is not attached to that DataContext. Therefore, the db DataContext cannot track the changes you’ve made to the object.

    You could try using DataContext.Attach or, even better, supply the form with the original data context the object was loaded from.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I implement this method (see below)? I'm new to Objective-C and I'm
For example I have this gem called Authlogic-openid, that plugin is outdated, no longer
I'm trying to write a method that will return a Hibernate object based on
Why are the lists list1Instance and p in the Main method of the below
How to implement method for IQuariable like below: var trash = (from a in
How can I select the good method (I have in the example below show
I would like to update my SQL lite database with the native update-method of
I'm getting an error here that says I haven't defined a method, but it
This is beyond both making sense and my control. That being said here is
I am creating a web service that queries my database and returns a list

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.