Is it possible to save a DataTable into SQL database in one cell of type binary for example and read it back again into a DataTable?
I would create, if possible, a xml field inside the sql database and save the datatable as xml
XML Support in Microsoft SQL Server 2005
and
C# and Vb.net example for XML data type tips in SQL Server 2005
should help you
another example took from here
protected bool LoadXml(SqlConnection cn, XmlDocument doc)
{
//Reading the xml from the database
string sql = @"SELECT Id, XmlField FROM TABLE_WITH_XML_FIELD WHERE Id = @Id";
SqlCommand cm = new SqlCommand(sql, cn);
cm.Parameters.Add(new SqlParameter("@Id",1));
using (SqlDataReader dr = cm.ExecuteReader())
{
if (dr.Read())
{
SqlXml MyXml= dr.GetSqlXml(dr.GetOrdinal("XmlField"));
doc.LoadXml( MyXml.Value);
return true;
}
else
{
return false;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With