DataTable dt = new DataTable();
using (OleDbDataAdapter da = new OleDbDataAdapter(@"select title as Title, publisher as Publisher, year as Year from books", @"Provider=VFPOLEDB.1;Data Source=c:\myvfp\"))
{
da.Fill(dt);
}
XElement xml = new XElement("books",
dt.AsEnumerable().Where(book =>
book.Field<int>("Year") == 2006)
.Select(book => new XElement("book",
new XAttribute(
"title",
book.Field<string>("Title")),
new XElement(
"publisher",
book.Field<string>("Publisher"))
))
);
Console.WriteLine(xml);
or
XElement xml = new XElement("books",
from book in dt.AsEnumerable()
where book.Field<int>("Year") == 2006
select new XElement("book",
new XAttribute("title", book.Field<string>("Title")),
new XElement("publisher", book.Field<string>("Publisher")
)));
Console.WriteLine(xml);
Instead of
from book in dt.AsEnumerable()
we can use
from DataRow book in dt.Rows
Saturday, January 3, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment