C# -- "tableAdapter" SAVE fails ?

finance_teacher
finance_teacher used Ask the Experts™
on
The below SAVES into my
"gML_ROITEM" database table.

How can I uncomment the below so
it also saves "GLOBAL_ItemID" into
my "gML_ROITEM" database table's
"IM_ID" column ?
------------------------------------------
        string GLOBAL_ItemID = "";

        private void sTOCKNUMTextBox_Leave(object sender, EventArgs e)
        {
            try
            {
                DataRow[] nDR = this.gmL_ITEMMSTRTableAdapter1.GetDataBy_vStockNumber(this.sTOCKNUMTextBox.Text).Select();
                if (nDR.Length <= 0)
                {
                    MessageBox.Show("Stock Number not found");
                }
                else
                {
                    GLOBAL_ItemID = nDR[0]["ID"].ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("");
            }
        }
------------------------------------------
        private void gML_ROITEMBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            //fails, works in DataGridView --> this.gML_ROITEMDataGridView.Rows[i].Cells["IM_ID"].Value = nDR[0]["ID"];
            //fails, how can I fix --> this.gML_ROITEMDataGridView.Rows[i].Cells["IM_ID"].Value = GLOBAL_ItemID;
            this.gML_ROITEMBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.dataSet1);
        }
0003.jpg
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
are you getting an error? could you post the error  you are having so we can see what it says.

Author

Commented:
Below Option #2 works.

How can I also get the below Option #1 to work, passing "GLOBAL_ItemID" into EndEdit / UpdateAll so I don't have to do like option #2 ?
----------------------------------------------------------------------------------
Option #1

        private void gML_ROITEMBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            //this.gML_ROITEMBindingSource.EndEdit();
            //this.tableAdapterManager.UpdateAll(this.dataSet1);
            MessageBox.Show("Saved");
        }

----------------------------------------------------------------------------------
Option #2

        private void gML_ROITEMBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.gML_ROITEMTableAdapter.Insert(1, 10, GLOBAL_ItemID, Decimal.Parse(pALLETSREQTextBox.Text), null, null, null, null, null, null, null, null, null, null,
                null, null, null, null, null, null);
            MessageBox.Show("Saved");
        }
Commented:
In your initial question you stated that you got errors and marked the code as "//fails"

You'll never get Option #1 to work unless we correct your original error...  If you don't update the row properly, there is nothing to update with the TableAdapter.

Could you try running your code again (UNcomment the '//fails'), and give us the error information so we can help you with this please.

Thanks,

Jake

Author

Commented:
Ok, I will retest.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial