Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to I retrieve Data from memory if...

Posted on 2003-03-07
5
Medium Priority
?
177 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
  • 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

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

564 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