Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DataRow to XML
Message
From
17/05/2004 15:15:20
 
 
General information
Forum:
ASP.NET
Category:
ADO.NET
Title:
Miscellaneous
Thread ID:
00904649
Message ID:
00904673
Views:
21
I was hoping it was that easy. I just tried it and it doesn't work. Now maybe there's another way to filter a DataTable... In my test I did
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim ds As New DataSet
    Dim dt As New DataTable("Names")
    dt.Columns.Add("ID", Type.GetType("System.Int32"))
    dt.Columns.Add("Name", Type.GetType("System.String"))
    dt.PrimaryKey = New DataColumn() {dt.Columns("ID")}

    Dim dr As DataRow = dt.NewRow()
    dr("ID") = 1
    dr("Name") = "Doe, John"
    dt.Rows.Add(dr)

    dr = dt.NewRow()
    dr("ID") = 2
    dr("Name") = "Sue, Bobby"
    dt.Rows.Add(dr)

    dr = dt.NewRow()
    dr("ID") = 3
    dr("Name") = "Diddlewhist, Klyde"
    dt.Rows.Add(dr)

    dr = dt.NewRow()
    dr("ID") = 4
    dr("Name") = "Bummblewartz, Jerry"
    dt.Rows.Add(dr)

    ds.Tables.Add(dt)
    ds.Tables("Names").DefaultView.RowFilter = "ID=2"

    Dim ms As New IO.MemoryStream
    ds.WriteXml(ms)
    Dim bytes() As Byte = ms.ToArray()
    Dim XmlString As New System.Text.StringBuilder(CInt(ms.Length))
    For Index As Integer = 0 To CInt(ms.Length - 1)
        XmlString.Append(Chr(bytes(Index)))
    Next
    TextBox1.Text = XmlString.ToString
End Sub
It still wrote out all the rows. Is there another way (other than through the DefaultView of the DataTable) to filter rows?

-----
Lee Perkins

>Lee,
>
>I haven't tried this myself, so take this as just a guess, but are you able to filter on just that row?
>
>I'm curious if the WriteXML function will honor a filter. Again, a complete guess, so I'm sure someone else may come along with something.
>
>Kevin
-----
Lee Perkins
TigerBase Technologies

"Lee is one that would plug his brain into the internet, if he could, and STILL scream for more" - Very good friend of Lee's
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform