Reputation: 5504
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:
CAST([info] AS VARCHAR(MAX))
), please let me know.Thanks in advance.
Upvotes: 0
Views: 832
Reputation: 17600
XDocument doc = XDocument.Parse(dataTable.Rows[r]["info"].ToString());
And then you can linq away
Upvotes: 2