Link to home
Start Free TrialLog in
Avatar of animated405
animated405

asked on

How to I retrieve Data from memory if...

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!!

Avatar of animated405
animated405

ASKER

Also, the error I'm getting is "the root element is missing"...if that helps
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
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)
ASKER CERTIFIED SOLUTION
Avatar of yosit
yosit

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks!!