2010-10-06 94 views
1

我有我的datagridview綁定到訪問表(訪問2007年)的問題,我可以從數據庫檢索數據,但是當我要存儲數據我不能,即使沒有代碼生成,我只是想用戶填寫一些列在DataGridView並將它們存儲在數據庫中的表,請幫我 我是新來的C#請幫我綁定到C#中的datagridview?

private void Form1_Load(object sender, EventArgs e) 
    { 
     // TODO: This line of code loads data into the 'policiasDataSet.LineaAccion' table. You can move, or remove it, as needed. 
     this.lineaAccionTableAdapter.Fill(this.policiasDataSet.LineaAccion); 
     // TODO: This line of code loads data into the 'policiasDataSet.Seccion' table. You can move, or remove it, as needed. 
     this.seccionTableAdapter.Fill(this.policiasDataSet.Seccion); 
     // TODO: This line of code loads data into the 'policiasDataSet.Actividad' table. You can move, or remove it, as needed. 
     this.actividadTableAdapter.Fill(this.policiasDataSet.Actividad); 
     // TODO: This line of code loads data into the 'policiasDataSet.Proyecto' table. You can move, or remove it, as needed. 
     this.proyectoTableAdapter.Fill(this.policiasDataSet.Proyecto); 
     // TODO: This line of code loads data into the 'policiasDataSet.ProyectoObjetivo' table. You can move, or remove it, as needed. 
     this.proyectoObjetivoTableAdapter.Fill(this.policiasDataSet.ProyectoObjetivo); 
     // TODO: This line of code loads data into the 'policiasDataSet.Objetivo' table. You can move, or remove it, as needed. 
     this.objetivoTableAdapter.Fill(this.policiasDataSet.Objetivo); 
     // TODO: This line of code loads data into the 'policiasDataSet.Municipio' table. You can move, or remove it, as needed. 
     this.municipioTableAdapter.Fill(this.policiasDataSet.Municipio); 
     // TODO: This line of code loads data into the 'policiasDataSet.Logro' table. You can move, or remove it, as needed. 
     this.logroTableAdapter.Fill(this.policiasDataSet.Logro); 

    } 

    private void fillByToolStripButton_Click(object sender, EventArgs e) 
    { 
     try 
     { 
      this.proyectoTableAdapter.FillBy(this.policiasDataSet.Proyecto); 
     } 
     catch (System.Exception ex) 
     { 
      System.Windows.Forms.MessageBox.Show(ex.Message); 
     } 

    } 

回答

1

很難知道,如果你不這裏發表您的源代碼發生什麼事。我想你可能想看看OleDBDataAdapter.Update(Datatable table)手冊。

+0

但是沒有代碼生成這個: – peggalvan 2010-10-07 00:42:34

+0

我已經編輯了代碼 – peggalvan 2010-10-07 00:45:07

+0

當你編輯你的datagridview時,你實際上是在工作「離線」數據(從你的查詢中檢索到的數據表)而不是數據庫中的數據直接。所以我認爲你需要以某種方式使用Update()函數同步你的datagridview的數據源和數據庫。 – Andy 2010-10-07 00:59:00