2017-01-21 3 views
0

dataGridViewの列の値を更新できません。助けてくださいdataGridViewの列の値を編集できません

  private void button1_Click(object sender, EventArgs e) 
     { 

      { 
      SqlDataAdapter adapter = new SqlDataAdapter(); 
      itemRecordBindingSource.EndEdit(); 
      DataTable dt = new DataTable(); 
      adapter.Update(dt);  
      MessageBox.Show("Record Saved."); 
     } 

     catch(Exception c) 
     { 
      MessageBox.Show("Sorry, could not update data." + c); 
     } 

    } 

それはまた、テーブルを更新していません。

+0

プラースペーストの完全なコードここでは、どのようにデータテーブルにデータを譲渡しているのか分かりません。 –

+0

これはデータベースのコード行です。このフォームにはこれ以上のコードはありません。 'private void itemedit_Load(オブジェクト送信者、EventArgs e) { this.itemRecordTableAdapter.Fill(this.managementDataSet2.ItemRecord); } ' – stackuser

+0

どのようにしてやるの?あなたは黒のdataTableを作成し、アダプタに送信し、更新をどのように期待していますか? –

答えて

0

データグリッドを編集可能にするために、グリッド内の列を編集した後に、そのグリッドをdbに保存するには、グリッド表示のこのイベントを使用してください。

I am assuming you are able to fill GridView with data if not first 
get the data from sql query and set the datasource of grifview to that table . once you have data then you can use this event . 


     private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) 
     { 

      try 
      { 
      -- here you can get the column index and column value 
      now based on the index and value you can witre you sql query/or a function which will update the database . 
      string value = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); 
      } 
      catch (Exception ex) 
      { 
       MessageBox.Show(ex.Message); 
      } 
     } 
関連する問題