Hello,
I am looking for sample code if any, to save configuration XML file to database instead of saving to file.
Code Sample:
UltraTilePanel1.SaveAsXml("PanelFile.XML")
Is there any way I can save it directly to database?
Please let me know if you need more information.
Thanks
Imran
Hi Imran,
The approach with Binary columns works properly (if you need a sample, let me know) . To be honest I prefer Binary approach instead of XML solution. Nevertheless if you want to use XML, you could use the similar approach with XmlReader
Let me know if you have any further questions.
Regards
Thanks Georgi for your reply.
I will verify and let you know my feedback.
Only concern I have, is there any way to store configuration as "XML" instead of "Binary" to database.
Cause in my situation, we are storing configuration as "XML" data type.
Hello Imran,
There are different approaches to solve this task. One possible solution could be if you are using the code below:
#1 How to save your settings in database:
private void ultraButton1_Click(object sender, EventArgs e)
{
byte[] byteArray = new byte[2048];
ultraTilePanel1.SaveAsXml(new MemoryStream(byteArray)); ;
SqlConnection conn = new SqlConnection("Data Source=IGBGSOFDS22;Initial Catalog=Test;Integrated Security=True");
conn.Open();
SqlCommand command2 = new SqlCommand("UPDATE [Table_A] set Binary = @Binary WHERE [ID] = 1", conn);
command2.Parameters.Add("@Binary", SqlDbType.VarBinary);
command2.Parameters["@Binary"].SqlValue = byteArray;
command2.ExecuteNonQuery();
ms.Close();
conn.Close();
}
#2 How to load your settings from database:
private void ultraButton4_Click(object sender, EventArgs e)
SqlCommand command2 = new SqlCommand("SELECT [Binary] FROM [Table_A] WHERE [ID] = 1", conn);
SqlDataReader myReader = command2.ExecuteReader();
while(myReader.Read())
MemoryStream ms = new MemoryStream((byte[])myReader.GetSqlBinary(0));
ultraTilePanel1.LoadFromXml(ms);
myReader.Close();
Let me know if you have any questions.