Fire query on DataSet

  • Thread starter Thread starter Arun Gupta via .NET 247
  • Start date Start date
A

Arun Gupta via .NET 247

DataSet is supposed to be an in-memory database. So is itpossible to fire a query on it. I want to fire a "Select" query(with alises in it) and also a "Transform" (Crosstab) query. Inthe current scenario I am putting things in an Access table butfor performance reasons want to deal with in-memory contents.

Thanks in advance.
 
It might be more helpful to think of the DataSet as an in-memory cache
rather than a database. It does not support SQL syntax the way a
database does. If you want to use Access functionality like crosstabl
queries, execute them in Access and load the results in the DataSet.

--Mary
 
Hi,

By default DataSet does not support any queries. What you could do is to
query database directly or to simulate query using XSL stylesheet. Here is an
example how to do this (assuming the Book3.xml is a DataSet file)

------------ VB code to run *query*

Dim loSourceXML As XPath.XPathDocument
Dim loTransform As Xsl.XslTransform
Dim loDataSet As DataSet
Dim loNewDataStream As MemoryStream
Dim loFilteredDataSet As DataSet

loDataSet = New DataSet()
loDataSet.ReadXml("Book3.xml")

loSourceXML = New XPath.XPathDocument(New
StringReader(loDataSet.GetXml()))

loTransform = New Xsl.XslTransform()
loTransform.Load("Transform.xsl")

loNewDataStream = New MemoryStream()

loTransform.Transform(loSourceXML, Nothing, loNewDataStream)
loFilteredDataSet = New DataSet()
loNewDataStream.Position = 0

loFilteredDataSet.ReadXml(loNewDataStream, XmlReadMode.Auto)
loFilteredDataSet.WriteXml("Filtered.xml")

--------------- Transform.xsl file content. It is actual *query*

<?xml version="1.0" ?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>

<xsl:template match="/MY_DATASET">

<xsl:element name="MY_FIELD_NAME">

<xsl:copy-of select="DETAIL[FIELD_TO_FILTER='XXXXX']" />

</xsl:element>

</xsl:template>

</xsl:stylesheet>
 
Back
Top