2014-01-28 59 views
0

我使用C#與Visual Studio 2010,使用綁定和Oracle數據源。表適配器綁定不更新

我的代碼塊如下

//This loads the information into the textbox 
     try 
     { 
      this.invoicePrimariesTableAdapter.FillByInvoiceID(this.nISSANDataset.InvoicePrimaries); 
     } 
     catch (System.Exception ex) 
     { 
      System.Windows.Forms.MessageBox.Show(ex.Message); 
     } 
     //This changes the contents of the textbox 
     int invoiceID = Convert.ToInt32(txtInvoiceNum.Text); 
     invoiceID += 1; 
     txtInvoiceNum.Text = Convert.ToString(invoiceID); 
     //This tries to update the Database, but fails 
     try 
     { 

      this.Validate(); 
      this.invoicePrimariesBindingSource.EndEdit(); 
      this.invoicePrimariesTableAdapter.Update(this.nISSANDataset.InvoicePrimaries);     
      MessageBox.Show("Update successful"); 
     } 
     catch (System.Exception ex) 
     { 
      MessageBox.Show("Hi" + ex); 
     } 

我找了1每次遞增該數據庫中的值的形式加載。這就是我所想的,但如果有更好的辦法,或者做出這種工作的方法,我會非常高興。

+0

更好的方法是更改​​DataRow而不是UI。 UI中的值只能通過UI和綁定進行更改。在代碼中直接在模型中更改數據。 – Ralf

+0

我的問題已解決。感謝您的幫助! – user3215251

回答

0

原來這一直都是我的錯。我忘記了我在數據庫中添加了另一列,但沒有更新我的C#項目中的數據源。它去更新2列表,而是找到了3列表並打破。