Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DataRow to XML
Message
General information
Forum:
ASP.NET
Category:
ADO.NET
Title:
Miscellaneous
Thread ID:
00904649
Message ID:
00904662
Views:
13
This message has been marked as a message which has helped to the initial question of the thread.
The idea of filtering the DataView sounds like a really good way to approach to the problem. However, I don't think the DataSet export will honor the filter. I have a function in one of my products that converts a DataView to a DataSet ... Below is the code that makes that happen:
    '* This routine is used to convert a DataView to a DataSet
    Public Shared Function DataViewToDataSet(ByVal dvToConvert As DataView) As DataSet

        ' Variables
        Dim dtRtn As New DataTable()
        Dim dsRtn As New DataSet()
        Dim drRtn As DataRow
        Dim nC1%, nC2%

        ' Assign Value / Stucture
        dtRtn = dvToConvert.Table.Copy

        ' Clear All Data
        dtRtn.Rows.Clear()

        ' Loop DataView
        For nC1 = 0 To (dvToConvert.Count - 1)

            ' Derive New Row
            drRtn = dtRtn.NewRow()

            ' Convert Data
            For nC2 = 0 To (dvToConvert.Table.Columns.Count - 1)
                drRtn(nC2) = dvToConvert(nC1)(nC2)
            Next

            dtRtn.Rows.Add(drRtn)

            ' Free Row
            drRtn = Nothing

        Next

        ' Append Table to DataSet
        dsRtn.Tables.Add(dtRtn)

        ' Return Data
        Return dsRtn

    End Function
You may could use the above code to help automate the process... In other words filter the view one record at a time and then convert the view to a DataSet and export it. Also, if you don't want to have to create a file for each record you can use to following code export to a memory stream which then converts to a string.
' Stream Values
Dim msMem As New System.IO.MemoryStream()

' Export
dsToExport.WriteXml(msMem, XmlWriteMode.WriteSchema)

' Variables
Dim oDcod As Decoder
Dim aChars() As Char
Dim sVar$

' Resize Array
ReDim aChars(CInt(msMem.Length))

' Setup Decoder
oDcod = Encoding.UTF8.GetDecoder()
oDcod.GetChars(msMem.GetBuffer(), 0, CInt(msMem.Length), aChars, 0)

' Convert to String
sVar = New String(aChars)

' Free Memory
oDcod = Nothing
aChars = Nothing
msMem.Close()
msMem = Nothing
Hope that helps...

Thanks,
Danny
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform