?
Solved

How to I retrieve Data from memory if...

Posted on 2003-03-07
5
Medium Priority
?
175 Views
Last Modified: 2010-04-15
New to .Net and confused. How can I store data in memory and then retrieve it for later use? Here is what I'm trying to do:

1. I want to get the data

2. then I loop through some custom configurations and for each one want to manipulate the data using xsl and then ftp that info to whomever is on the list to receive my catalogue of products. I don't want to get the data through each iteration because that would take way too long and doesn't make sense.

Here is what I've got for the initial page(i've left out the other built in things I'm using and have only included the namespaces I made):

using XMLTrans;
using getData;

public class Test
{
     static void Main()
     {

          Data myData = new Data();

          try
          {

               
//go though each unique configuration and ftp the file using this xsl tranformation
XMLTransform myTransform = new XMLTransform(_configuration-setting-here_);

                    }
               }

          }
          catch(Exception e)
          {
               Console.WriteLine("Caught Error :"+e.Message);
          }
         
     }    
         
}
     
So, at the very beginning of this page it calls Data, which is as follows and is where I'm trying to set the returned dataset into memory:


namespace getData
{
     public class Data
     {
          private string sSQL = System.Configuration.ConfigurationSettings.AppSettings["sql"];
          private string sServer = System.Configuration.ConfigurationSettings.AppSettings["server"];
          private string sUID = System.Configuration.ConfigurationSettings.AppSettings["uid"];
          private string sPWD = System.Configuration.ConfigurationSettings.AppSettings["pwd"];
          private string sDB = System.Configuration.ConfigurationSettings.AppSettings["db"];

          public Data()
          {
               DataSet ds = new DataSet("NewDataSet");
               SqlConnection conn = new SqlConnection("server=" + sServer + ";uid=" + sUID + ";pwd=" + sPWD + ";database=" + sDB + "");
               SqlDataAdapter da = new SqlDataAdapter(sSQL,conn);

               
               MemoryStream memStrm = new MemoryStream();
               StreamWriter strmWrite = new StreamWriter(memStrm);


               ds.WriteXml(strmWrite,XmlWriteMode.IgnoreSchema);
               memStrm.Seek(0,SeekOrigin.Begin);

               da.Fill(ds,"product");
               DataTable oDT = ds.Tables["product"];

          }
     }
}


Thsn as I loop through each config file I want to call my XSLTransform that is using and do as follows, which is where it's failing (indicated between the **********)when I try to set the new XslTransformation to the StreamReader:

namespace XMLTrans
{
     public class XMLTransform
     {
          private System.Xml.XPath.XPathDocument xpthDoc;
          private System.Xml.Xsl.XslTransform xsltWorker;
               
          private XmlDocument doc = new XmlDocument();

          public XMLTransform(string datafeed)
          {
               
               MemoryStream memStrm = new MemoryStream();

               StreamReader strmRead = new StreamReader(memStrm);

               this.xsltWorker= new XslTransform();

               
               this.xsltWorker.Load("http://localhost/gohere/" + datafeed + ".xsl");
**********
               this.xpthDoc = new XPathDocument(strmRead);
**********
               StreamWriter sw = new StreamWriter(@"c:\datafeeds\" + datafeed + ".txt");

               xsltWorker.Transform(xpthDoc,null,sw);

               XmlNodeList nodeLst = doc.GetElementsByTagName("NewDataSet");


               sw.Close();
          }
     }
}


I'm very fuzzy on the MemoryStream stuff here. Any help would be much appreciated, thanks!!

0
Comment
Question by:animated405
[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
  • 2
5 Comments
 

Author Comment

by:animated405
ID: 8091156
Also, the error I'm getting is "the root element is missing"...if that helps
0
 
LVL 1

Expert Comment

by:yosit
ID: 8094635
as a simple way you could store it in a static variable at the start of your program (watch about threads).

if u need it crossprocess - you need to implement it your self using memory mapped files or Remoting(singleton style).


yosi
0
 

Author Comment

by:animated405
ID: 8104212
How do I store a dataset as a variable? What would be the variable type when passing that into something else, for example:

public thisthing(string datafeedtype)
0
 
LVL 1

Accepted Solution

by:
yosit earned 500 total points
ID: 8109369
here is an example:

class Test
{
    private DataSet mData;
    public Test(DataSet data)
        {
                mData = data;
        }
    public DataSet Data
     {
          get
          {
               return mData;
          }
     }
}

we pass the dataset to the CTOR of the class.
the type of the varialbe is DataSet (in system.data namespace)

have fun,
yosi
0
 

Author Comment

by:animated405
ID: 8112443
thanks!!
0

Featured Post

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.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

752 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