Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: WPF save dataset to xml

Lee Barry:

I have tried to read/save xml file to Datagrid and I'm using Dataset to do it. Now I have succeed to load xml file data to datagrid, the code as follows:


public class StoreDbDataSet
{
public DataTable GetProducts()
{
return ReadDataSet().Tables[0];
}

internal static DataSet ReadDataSet()
{
DataSet ds = new DataSet();
ds.ReadXmlSchema("store.xsd");
ds.ReadXml("store.xml");
return ds;
}

}

And:


public class StoreDb
{
public ObservableCollection GetProducts()
{
DataSet ds = StoreDbDataSet.ReadDataSet();

ObservableCollection products = new ObservableCollection();
foreach (DataRow productRow in ds.Tables["Products"].Rows)
{
products.Add(new Product((string)productRow["ModelNumber"],
(string)productRow["ModelName"], (string)productRow["InputAddress"],
(string)productRow["OutputAddress"], (string)productRow["DiagAddress"],
(string)productRow["Description"], (byte)productRow["CategoryID"],
(string)productRow["CategoryName"], (string)productRow["ProductImage"]));
}
return products;
}
}

Xaml File:














The ViewModel:


public ICollectionView ProductsView
{
get { return _ProductsView; }
set
{
_ProductsView = value;
NotifyPropertyChanged();
}
}

My question is when I changed the datagrid data, how can I save the changes to xml?Thanks in advance!



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: WPF save dataset to xml

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×