I'm trying to pass a DataTable between C# and SQL Server both ways. I'm currently using XML to facilitate this, but I'm struggling to deserialize the XML both ways (i.e. to deserialize the C# XML in SQL Server, and to deserialize the SQL Server XML in C#). I'm currently using the following procedure to create the XML in C#:
var dt = new DataTable();
//Populate the DataTable...
var set = new DataSet();
set.Tables.Add(dt);
var sb = new StringBuilder();
using (var stringWriter = new StringWriter(sb))
{
set.WriteXml(stringWriter);
}
string xml = sb.ToString();
I'd then like to be able to parse this XML in SQL Server. Is there a way to automatically parse this as a DataTable in SQL Server (using a schema I would suppose)?