keyongtech


  keyongtech > dotnet.framework.* > dotnet.framework.adonet > 12/2004

 #1  
12-08-04, 09:51 PM
deko
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.
 #2  
12-09-04, 12:20 AM
W.G. Ryan eMVP
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.
 #3  
12-09-04, 12:56 AM
deko
> 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.


Hi and thanks for the reply. But I'm a bit confused. In your first
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!
Similar Threads
dataset and dataview

If I set a dataview to equal a table in a dataset, then filter that dataview, how can I reflect this back into my dataset? TIA, Amber

Strongly typed dataset, sorted by dataview, how to get dataset's row index from dataview?

Hello everyone, here's my problem! I'm using the .NET framework v1.1... I've created a strongly-typed dataset class (using XML), and I've instantiated it twice. The first...

SQL Table to DataSet to Dataview, to DataSet to XML!

Hi everybody, i've a question for this group: i've developed a windows service that every x minutes count records present in a sql table and if those records are bigger than...

DataView / DataSet / ADO.NET HELP

Ok I want to filter a dataset into a dataview and be able to reference back to the dataset from the filtered dataview. Example: 100 record dataset filter it to a 5 record...

DataView vs. DataSet

Hello Few things to remove the cloud: 1) Can a DataView be a subset of a DataSet ? 2) DataSet consists of tables, is that different from a DataTable object ? 3) In IDE,...


All times are GMT. The time now is 06:50 PM. | Privacy Policy