Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6645477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:17:32+00:00 2026-05-26T00:17:32+00:00

I have cached a dataset which has StoreId column. When I want to export

  • 0

I have cached a dataset which has “StoreId” column.
When I want to export the dataset to Excel I suppose to remove the “StoreId” column from the dataset and Exprot.

Following is the code for Removing and Exporting to Excel.

if (HttpContext.Current.Cache["stores"] != null)
        {
            using (DataSet dsStores = (DataSet)HttpContext.Current.Cache["stores"])
            {
                if (TrainingUtil.isDataSetValid(dsStores))
                {
                    DataTable dt = dsStores.Tables[0];
                    dt.Columns.Remove("storeId");
                    Quality.Qulaity_Utility.ExportDataSet(dt, ddlCity.SelectedItem.Text.ToString() + "_StoreCodes");
                }

            }
        }

  public static void ExportDataSet(DataTable dt,string filename)
    {
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.Buffer = true;
        HttpContext.Current.Response.ContentType = "application/vnd.xls";
        HttpContext.Current.Response.Charset = "";
        HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + filename.Replace(" ", "_").ToString() + ".xls");

        DataGrid dgRecord = new DataGrid();
        //Color Setttings
        dgRecord.HeaderStyle.BackColor = System.Drawing.Color.Cyan;

        dgRecord.DataSource = dt;
        dgRecord.DataBind();

        //Cells color settings
        foreach (DataGridItem dgi in dgRecord.Items)
        {
            foreach (TableCell tcGridCells in dgi.Cells)
            {
                tcGridCells.Attributes.Add("class", "sborder");
            }
        }
        //Render the datagrid

        StringWriter stringWriter = new StringWriter();
        HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
        dgRecord.RenderControl(htmlTextWriter);
        //lstMonthlyReport.RenderControl(htmlTextWriter);
        //Add the style sheet class here
        HttpContext.Current.Response.Write(@"<style> .sborder { color : Black;border : 1px Solid Black; } </style> ");
        //Export
        HttpContext.Current.Response.Write(stringWriter.ToString());
        //End
        HttpContext.Current.Response.End();
        //style to format numbers to string
        //string style = @"<style> body { mso-number-format:\@; } </style>";
    }
}

after exporting the data and When I once againg want Stores information from Cached dataset
I was unable to find the “StoreId” Column,
I’m unable figure out where I’m doing wrong.
Plz help me out.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:17:32+00:00Added an answer on May 26, 2026 at 12:17 am

    You will make your life easier if you never modify objects you put in Cache. Removing columns from a DataSet is not thread-safe, so if multiple requests access the Cache concurrently, you’re in trouble.

    In this case, I would create a clone of the DataSet and export the clone. To do so, use the DataSet.Copy method:

    DataSet dsStores = ((DataSet)HttpContext.Current.Cache["stores"]).Copy()
    

    Or find a way of doing the export that doesn’t require you to modify the DataSet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a cache which has soft references to the cached objects. I am
I have an ASP.net page which has fields for filtering a dataset. When I
The problem is quite basic. I have a JTable showing cached data from a
I need to read from a dataset which is very large, highly interlinked, the
I have the following model class Plugin(models.Model): name = models.CharField(max_length=50) # more fields which
I have an entity (JPA annotations with Hibernate query interface) which has a composite
I have a collection which I want to show totals for, and the idea
Whenever I try to get a bitmap I have cached from the context I
I have a problem of web pages being cached even though I specify that
Image i have a view that is cached with the OutputCache attribute but i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.