Solved

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

Posted on 2012-04-11
6
398 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

759 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now