2017-02-09 1 views
0

OleDBCommandBuilder 및 입력 된 데이터 집합으로 DB를 업데이트 할 때 문제가 있습니다. 준비된 패널로 데이터베이스를 편집 할 때, 업데이트 후에 DataGridView에서 변경 사항이 발생합니다. 그러나 이러한 변경은 일시적입니다. 응용 프로그램을 다시 시작하면 변경 사항이 데이터베이스의 원래 정보로 바뀝니다. 누구나 아래에 주어진 코드 문제를 볼 수 있습니까?C# 테이블 어댑터를 업데이트해도 DB가 업데이트되지 않습니다.

var row = this.dataGridViewProducts.SelectedRows[0]; 
     DataRowView rowView = row.DataBoundItem as DataRowView; 
     ProductsRow productRow = rowView.Row as ProductsRow; 
     if (row != null) 
     { 
      ProductForm formEdit = new ProductForm(ref productRow); 
      bool success = false; 
      while (success == false) 
      { 
       try 
       { 
        formEdit.ShowDialog(); 
        if (this.productsTableAdapter1.Connection.State != ConnectionState.Open) 
         this.productsTableAdapter1.Connection.Open(); 
        var changes = nwindDataSet1.Products.GetChanges(); 
        if (changes != null) 
        { 
         OleDbCommandBuilder builder = new OleDbCommandBuilder(productsTableAdapter1.Adapter); 
         productsTableAdapter1.Adapter.UpdateCommand = builder.GetUpdateCommand(); 
         productsTableAdapter1.Adapter.Update(changes); 
         nwindDataSet1.Products.AcceptChanges(); 
        } 
        success = true; 
       } 
       catch (Exception error) 
       { 
        MessageBox.Show(error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 
       } 

      } 
     } 

답변

관련 문제