|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DataSet vs. DataView - How to update?is wrapped in a DataView and bound to various controls through which users will make changes to the data, and when the "Save and Close" button on my form is clicked, the changes persist back to XML using XmlDataDocument. My question is this: Should I update the DataView or the DataSet? An example of updating the DataSet might look like this: public static void newLst(DataSet xdd) { DataView dv = null; dv = new DataView ( xdd.Tables["Configuration"], "ProjectName = 'UnassignedConfiguration'", "ConfigurationName", DataViewRowState.CurrentRows ); //dv.AllowEdit = true; //dv.AllowNew = true; //dv.AllowDelete = true; //why would I want to use the above methods rather than updating the DataSet directly? } An example of updating the DataSet might look like this: public static void chgNam ( DataSet xdd, string oldNam, string newNam, string tblNam ) { DataTable dt = xdd.Tables[tblNam]; DataRow dr = dt.Rows.Find(oldNam); dr[tblNam + "Name"] = newNam; } Suggestions or comments welcome! Thanks in advance. You'd want to use those methods becuase anything you do to the DataView will
be done to the underlying table and you will want to bind to a filtered view in many instances, instead of a dataTable. Just update the dataTable that the view is based on and you'll be in good shape (Update as in the DataAdapter) for client side editing, editing the view will be fine. -- Show quoteW.G. Ryan MVP (Windows Embedded) TiBA Solutions www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com "deko" <www.clearpointsystems.com@use_contact_form.com> wrote in message news:cHKtd.30942$zx1.28316@newssvr13.news.prodigy.com... > I have a WinForms app that builds a DataSet from an XML file. The DataSet > is wrapped in a DataView and bound to various controls through which users > will make changes to the data, and when the "Save and Close" button on my > form is clicked, the changes persist back to XML using XmlDataDocument. > > My question is this: Should I update the DataView or the DataSet? > > An example of updating the DataSet might look like this: > > public static void newLst(DataSet xdd) > { > DataView dv = null; > dv = new DataView ( > xdd.Tables["Configuration"], > "ProjectName = 'UnassignedConfiguration'", > "ConfigurationName", > DataViewRowState.CurrentRows > ); > //dv.AllowEdit = true; > //dv.AllowNew = true; > //dv.AllowDelete = true; > //why would I want to use the above methods rather than updating the DataSet > directly? > } > > An example of updating the DataSet might look like this: > > public static void chgNam > ( > DataSet xdd, > string oldNam, > string newNam, > string tblNam > ) > { > DataTable dt = xdd.Tables[tblNam]; > DataRow dr = dt.Rows.Find(oldNam); > dr[tblNam + "Name"] = newNam; > } > > Suggestions or comments welcome! > > Thanks in advance. > > > You'd want to use those methods becuase anything you do to the DataView Hi and thanks for the reply. But I'm a bit confused. In your firstwill > be done to the underlying table and you will want to bind to a filtered view > in many instances, instead of a dataTable. > > Just update the dataTable that the view is based on and you'll be in good > shape (Update as in the DataAdapter) for client side editing, editing the > view will be fine. paragraph you seem to advocate updating the DataView with methods such as: dv.AllowEdit = true; dv.AllowNew = true; dv.AllowDelete = true; But in your second paragraph you suggest that I should "Just update the dataTable that the view is based on" - with methods such as: DataTable dt = xdd.Tables[tblNam]; DataRow dr = dt.Rows.Find(oldValue); dr["RowName"] = newValue; Sorry if I've missed your meaning... can you please clarify? It would seem to me that since the DataView is simply a wrapper for the DataTable that updating the DataTable directly (my second example) would be better. But then how do I refresh the DataView to which the controls are bound? Would I use something like this: public static void newLst(DataSet xdd) { DataView dv = null; //dump the old DataView dv = new DataView //create new DataView ( xdd.Tables["TableName"], "RowName" = 'myRow'", "SortByValue", DataViewRowState.CurrentRows ); } Thanks for your help! |
|||||||||||||||||||||||