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(_configuratio n-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.Confi gurationSe ttings.App Settings[" sql"];
private string sServer = System.Configuration.Confi gurationSe ttings.App Settings[" server"];
private string sUID = System.Configuration.Confi gurationSe ttings.App Settings[" uid"];
private string sPWD = System.Configuration.Confi gurationSe ttings.App Settings[" pwd"];
private string sDB = System.Configuration.Confi gurationSe ttings.App Settings[" 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,XmlW riteMode.I gnoreSchem a);
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.XPathDocu ment xpthDoc;
private System.Xml.Xsl.XslTransfor m 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:\datafeed s\" + datafeed + ".txt");
xsltWorker.Transform(xpthD oc,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!!
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(_configuratio
}
}
}
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.Confi
private string sServer = System.Configuration.Confi
private string sUID = System.Configuration.Confi
private string sPWD = System.Configuration.Confi
private string sDB = System.Configuration.Confi
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,XmlW
memStrm.Seek(0,SeekOrigin.
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.XPathDocu
private System.Xml.Xsl.XslTransfor
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:\datafeed
xsltWorker.Transform(xpthD
XmlNodeList nodeLst = doc.GetElementsByTagName("
sw.Close();
}
}
}
I'm very fuzzy on the MemoryStream stuff here. Any help would be much appreciated, thanks!!
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
if u need it crossprocess - you need to implement it your self using memory mapped files or Remoting(singleton style).
yosi
ASKER
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)
public thisthing(string datafeedtype)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks!!
ASKER