0

I am using divexpress pivotgrid control.

I want to do save and restore the layout. I can do that simply by using Session. But I don't know how to save it into my SQL Database.

This code without database UPDATED

protected void ASPxButton1_Click(object sender, EventArgs e)
{
    Session["Layout"] = ASPxPivotGrid1.SaveLayoutToString();

    MemoryStream stream = new MemoryStream(byteArray);

    string cs = ConfigurationManager.ConnectionStrings["HQWebMatajer13"].ConnectionString;
    using (SqlConnection con = new SqlConnection(cs))
    {
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandText = "INSERT INTO [HQWebMatajer].[dbo].[ReportSave]([UserID],[ReportName],[UserFileName],[ReportData])VALUES('faisal.3012','TotalSales','faisalxxx',@ReportData)";
        cmd.Parameters.AddWithValue("@ReportData", stream);

        con.Open();
        cmd.ExecuteNonQuery();
    }
    //divServer.InnerHtml = Session["Layout"].ToString();
}

protected void ASPxButton2_Click(object sender, EventArgs e)
{
    string text = "";
    string cs = ConfigurationManager.ConnectionStrings["HQWebMatajer13"].ConnectionString;
    using (SqlConnection con = new SqlConnection(cs))
    {
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandText = "select reportdata from [HQWebMatajer].[dbo].[ReportSave] where UserID='faisal.3012'";

        con.Open();

        string xxx = cmd.ExecuteScalar().ToString();
        StreamReader reader = new StreamReader(xxx);
        text = reader.ReadToEnd();
    }
    ASPxPivotGrid1.LoadLayoutFromString(text);
}

UPDATE: Saving to database is working, but when i try to restore from database it throws the following error

System.IO.FileNotFoundException: Could not find file 'C:\Program Files (x86)\IIS Express\System.Byte[].

on this line

StreamReader reader = new StreamReader(xxx);

I don't know any idea about how to convert and where to convert. The same question asked in devexpress in this link.. They referred to this stackoverflow. But the convertion I don't understand how to make it into my scenario.

Thanks

Community
  • 1
  • 1
Liam neesan
  • 2,282
  • 6
  • 33
  • 72

1 Answers1

0
select reportdata from [HQWebMatajer].[dbo].[ReportSave] where UserID='faisal.3012'

You check what is the output of the above line in the DB.

You may have not initialized the variable byteArray with grid data. Break code at

        MemoryStream stream = new MemoryStream(byteArray);

and check what you are storing in to DB.

udaya kumar
  • 169
  • 8