Solved

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

Posted on 2012-04-11
6
402 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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

Independent Software Vendors: 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!

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 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