Solved

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

Posted on 2012-04-11
6
399 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

867 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

16 Experts available now in Live!

Get 1:1 Help Now