Nick Vaccaro
Nick Vaccaro

Reputation: 5504

XML - From SQL Server to LINQ to XML

Setup:

I have some xml data stored in a database (SQL Server 2008 R2) which is retrieved via stored proc and placed into a DataTable. The DataTable has 2 columns: a DateTime "timestamp", and an XML "info".

After pulling this data from the database, I would like to loop through each row and operate on the data using LINQ to XML in C#.

public static void ParseDataTable(DataTable dataTable)
{
    for (int r = 0; r < dataTable.Rows.Count; r++)
    {
        // dataTable.Rows[r]["timestamp"].ToString() holds DateTime
        // dataTable.Rows[r]["info"].ToString() holds XML
    }
}

My Question:

What is the simplest way to get this data into an object on which I can use LINQ? What types of objects should be used?

Furthermore:

Thanks in advance.

Upvotes: 0

Views: 832

Answers (1)

Johan Larsson
Johan Larsson

Reputation: 17600

XDocument doc = XDocument.Parse(dataTable.Rows[r]["info"].ToString());

And then you can linq away

Upvotes: 2

Related Questions