troubleshooting Question

C# -- DataGridView -- "ID" autogenerated

Avatar of finance_teacher
finance_teacher asked on
.NET ProgrammingC#
8 Comments3 Solutions846 ViewsLast Modified:
My current C# APP requires me to
 1. enter anything in the "ID" field (attached 1.jpg)
 2. click submit
 3. attached 2.jpg get updated in database with
    autogenerated "ID = 139266" based on below code

I then try to do the same thing without an "ID"
since it will automatically get created below,
but I get the attached 3.jpg

How can I fix ?
        private void btn_Submit_Click(object sender, EventArgs e)
            this.dataSet1.EnforceConstraints = false;
            decimal iGML_ROMSTR_ID = 0;
                DataSet1TableAdapters.GML_SEQ_ROMSTRTableAdapter_ adpSeq = new MenuByUser.DataSet1TableAdapters.GML_SEQ_ROMSTRTableAdapter_();
                DataSet1.GML_SEQ_ROMSTRDataTable tb = adpSeq.GetData();

                if (tb != null && tb.Rows.Count > 0)
                    if (tb.Rows[0][0] != DBNull.Value)
                        iGML_ROMSTR_ID = Convert.ToDecimal(tb.Rows[0][0]);
                if (iGML_ROMSTR_ID <= 0)
                    iGML_ROMSTR_ID = 1;

                decimal TEMP_locNum = 0;
                decimal TEMP_palletsReq = 0;
                decimal TEMP_imId = 0;
                string TEMP_Priority = String.Empty;

                for (int i = 0; i < gML_ROITEMDataGridView.Rows.Count - 1; i++)
                    TEMP_locNum = (decimal)this.gML_ROITEMDataGridView["dataGridViewTextBoxColumn2", i].Value;
                    TEMP_imId = (decimal)this.gML_ROITEMDataGridView["dataGridViewTextBoxColumn3", i].Value;
                    TEMP_palletsReq = (decimal)this.gML_ROITEMDataGridView["dataGridViewTextBoxColumn4", i].Value;
                    TEMP_Priority = this.gML_ROITEMDataGridView["dataGridViewTextBoxColumn5", i].Value.ToString();
                    //below inserts locnum-itemID-pallets-pri-date-user-RO#-vend#
                    this.gML_ROITEMTableAdapter.InsertQuery(TEMP_locNum, 177982, TEMP_palletsReq, TEMP_Priority, DateTime.Today, 42, iGML_ROMSTR_ID, Convert.ToDecimal(this.cboVendor.SelectedValue.ToString()));
            catch (Exception ex)
                MessageBox.Show("Assign Error-> " + ex.Message);
Craig Wagner
Software Architect

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 3 Answers and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros