[ L a d y @ 30.01.2007. 10:06 ] @
Kako se nakon promena u DataGridView vrsi update baze? |
[ L a d y @ 30.01.2007. 10:06 ] @
[ ads @ 30.01.2007. 10:11 ] @
Imas super primer ovde
[ L a d y @ 30.01.2007. 17:09 ] @
Da li se update moze izvrsiti kroz pogled (view), ili samo kroz tabelu?
[ BezPanike @ 30.01.2007. 20:08 ] @
Može UPDATE i za view.
[ L a d y @ 30.01.2007. 21:43 ] @
Primer je dobar kod izmene sadrzaja tabele. Ako se isti kod upotrebi za izmenu sadrzaja preko pogleda, javlja se Error 7: 'prog.pDataSetTableAdapters.NTableAdapter' does not contain a definition for 'Update'. U cemu je poenta?
[quote]public partial class MainForm: Form { public MainForm() { InitializeComponent(); } private void MainForm_Load( object sender, EventArgs e) { this.regionTableAdapter.Fill( this.northwindDataSet.Region); // resize the column once, but allow the // users to change it. this.regionDataGridView.AutoResizeColumns( DataGridViewAutoSizeColumnsMode.AllCells); } //tracks for PositionChanged event last row private DataRow LastDataRow = null; /// <SUMMARY> /// Checks if there is a row with changes and /// writes it to the database /// </SUMMARY> private void UpdateRowToDatabase() { if (LastDataRow!=null) { if (LastDataRow.RowState== DataRowState.Modified) { regionTableAdapter.Update(LastDataRow); } } } private void regionBindingSource_PositionChanged( object sender, EventArgs e) { // if the user moves to a new row, check if the // last row was changed BindingSource thisBindingSource = (BindingSource)sender; DataRow ThisDataRow= ((DataRowView)thisBindingSource.Current).Row; if (ThisDataRow==LastDataRow) { // we need to avoid to write a datarow to the // database when it is still processed. Otherwise // we get a problem with the event handling of //the DataTable. throw new ApplicationException("It seems the" + " PositionChanged event was fired twice for" + " the same row"); } UpdateRowToDatabase(); // track the current row for next // PositionChanged event LastDataRow = ThisDataRow; } private void MainForm_FormClosed( object sender, FormClosedEventArgs e) { UpdateRowToDatabase(); } } Copyright (C) 2001-2025 by www.elitesecurity.org. All rights reserved.
|