Query an Existing DataSet into a New DataSet

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an existing Dataset, can I create a new Dataset using the existing dataset with a new Query. I want to query the existing dataset into a new dataset. Is this possible?
 
Not quite sure what you are after, but you may want to look at the Copy and Clone methods of the DataSet.

--Michael
 
Hi,

You could loop or you could use a stylesheet. Assuming that your dataset has
a MYDS name and table inside of it has a MYTABLE name. If you would like to
filter on a column ColumnA, then your stylesheet would look like (save it as
Transform.xsl file)


<?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="/MYDS">

<xsl:element name="MYDS">

<xsl:copy-of select="MYTABLE[ColumnA='AAA']" />

</xsl:element>

</xsl:template>

</xsl:stylesheet>

Your VB code would look like


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

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

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

loNewDataStream = New MemoryStream()

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

loFilteredDataSet.ReadXml(loNewDataStream, XmlReadMode.Auto)
 
Back
Top