ACP
ACP

Reputation: 35268

How to create an xml file from a database table using linq?

I have a sql server 2005 database which contains a user table.. Is it possible to create xml file from the user table? It contains columns like name,age,emailId,mob no etc.. Any suggestion?

Upvotes: 1

Views: 697

Answers (4)

Robert Rossney
Robert Rossney

Reputation: 96750

Consider just using an ADO.NET DataSet. It's got built-in XML serialization, and a bunch of other stuff that comes in handy when you're interoperating with a database.

Upvotes: 0

Aim Kai
Aim Kai

Reputation: 2909

This article may well help you..

http://jacquesbron.com/blog/database/linq-to-sql-and-linq-to-xml-in-action-from-database-to-xml/

I would use Entity Framework or Linq to SQL to get the data out of the database, then use linq to xml to create the desired xml output.

Upvotes: 1

Tim Croydon
Tim Croydon

Reputation: 1896

Assuming you can load the data from the DB table, then Linq to XML is exactly what you need. Check out the System.Xml.Linq namespace.

There are loads of tutorials around, but looking at the MSDN reference for XDocument isn't a bad place to start:

http://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument.aspx

I found this tutorial useful for getting me going when I first needed to do this:

http://www.hookedonlinq.com/LINQtoXML5MinuteOverview.ashx

Upvotes: 1

Michael Sagalovich
Michael Sagalovich

Reputation: 2549

Just serialize it. XmlSerializer or DataContractSerializer may help.

Upvotes: 0

Related Questions