c# - datagridview changes do not reflect in dataset ties to -


i have windows form has datagridview object in , use following code set datasource of dgv object:

private void form1_load(object sender, eventargs e) {     notesdataset = notesclient.getpatientnotes("6236321.00");      datagridview1.datasource = notesdataset.tables[0]; } 

notesclient.getpatientnotes()n retrieving of data , returns correct dataset. matter of fact acutally see data in dgv. problem after change values in dgv , use following code in save button:

notesdataset.acceptchanges(); if (notesdataset.haschanges())    {        dataset editdataset = notesdataset.getchanges();        notesclient.updatepatientnotes(editdataset);    } 

the if block not executed there no changes dataset @ all. know there no changes directly dataset isn't whole purpose of binding dgv datasource changes dgv reflected in dataset, missing changes not being transfered dataset. new c# , using prior programming exp assumed binding dgv datasource show changes in dgv dataset , vice versa? incorrect in assuming that?

it makes sense code block not executing because evaluate false when called directly after acceptchanges.

acceptchanges() changes datarow's rowstate added or modified unchanged, or deleted removed.

therefore when evaluate haschanges(), return false in case.

if want perform action on rows contain changes, want call methods before call acceptchanges().

edit:

brief example of think code should perform correctly:

    if (notesdataset.haschanges())     {         dataset editdataset = notesdataset.getchanges();         notesclient.updatepatientnotes(editdataset);     }     notesdataset.acceptchanges(); 

this way still calling updatepatientnotes method , have editdataset showing changes in dataset. , after execute if block, acceptchanges().

hope helps somehow.


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -