Solved

write datable to memory stream... cant read from stream

Posted on 2012-04-11
6
401 Views
Last Modified: 2012-08-14
Hi Guys,

I have built a website that allows user to upload csv file to datatable.  Maybe I don't quite understand the purpose of memory stream.

I write to stream by the below code


thanks!!

public partial class _Default : System.Web.UI.Page
{

    DataTable table;
    DataTable table2;
    protected DataTable dtable;
    MemoryStream memStm = new MemoryStream();

    protected void Unnamed2_Click(object sender, EventArgs e)
    {
...create table here
        table.AcceptChanges();

        GridView1.DataSource = table;
        GridView1.DataBind();

        table.WriteXml(memStm,XmlWriteMode.WriteSchema);
        memStm.Seek(0, System.IO.SeekOrigin.Begin);
}}

Open in new window



then in a new section

    protected void Button1_Click(object sender, EventArgs e) //launch program
    {

        DataTable newTable = new DataTable();
        memStm.Seek(0, System.IO.SeekOrigin.Begin);
        newTable.ReadXml(memStm);

        GridView2.DataSource = newTable;
        GridView2.DataBind();

Open in new window



I thought when I wrote to memory, I could always access it, any ideas what I'm doing wrong?

thanks
0
Comment
Question by:solarissf
  • 3
  • 3
6 Comments
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37833925
because its an asp.net page, every request will be handled by fresh instance of Default page handler.
for you to save datatable to be used across your page postbacks, just save it in session as:-

protected void Unnamed2_Click(object sender, EventArgs e)
    {
...create table here
        table.AcceptChanges();

        GridView1.DataSource = table;
        GridView1.DataBind();

        Session["table"]=table;
}

protected void Button1_Click(object sender, EventArgs e) //launch program
    {

        DataTable newTable = Session["table"] as DataTable;

        GridView2.DataSource = newTable;
        GridView2.DataBind();
}
0
 

Author Comment

by:solarissf
ID: 37833946
I was told that if I save in session, once the table gets huge, which it will, user performance will suffer and the page will take forever to load.  Is this true?
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37834036
in that case i think you should go for jquery ui and get the data using ajax and bind it on client side.
by doing so you can only fetch the data that is new and append it on client side....
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:solarissf
ID: 37834048
sorry, above my knowledge spectrum.  Before I get into learning that method, what if I write the xml to the actual server, then delete it at end of method?

I didn't want to do that at first though.  What are the benefits/drawbacks from using your method vs writing to server?

thanks
0
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 500 total points
ID: 37834061
in case of xml you have to save as many xml files as number of requests to your page.
then you should know which xml to bind to which user.

That's practically impossible, if your datatable has less than say 1000 rows, go for session, otherwise jquery/ajax...

you can also use paging in gridview to limited number of data from from datatable to your markup....

Remember, session data doesn't travel back to client, it remains in IIS Memory only.....
0
 

Author Comment

by:solarissf
ID: 37834093
thank you very much,,this cleared up alot.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
asp day pilot 3 23
Javascript to set controls visibility 5 48
Generate Unique ID in VB.NET 21 62
ASP.NET Content Page 3 29
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question