Solved

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

Posted on 2012-04-11
6
403 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
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…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

707 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