Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
545
Looking for Sample code or way to store UltraTilePanel Configurations to database instead of file on disk
posted

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

Parents
  • 53790
    Verified Answer
    posted

    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)

    {

      SqlConnection conn = new SqlConnection("Data Source=IGBGSOFDS22;Initial Catalog=Test;Integrated Security=True");

        conn.Open();

       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();

    conn.Close();

    }

    Let me know if you have any questions.

    Regards

Reply Children