Results 1 to 2 of 2

Thread: Binding a string of xml to a datagrid

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    Newcastle,UK
    Posts
    66

    Binding a string of xml to a datagrid

    Hiya,

    This is probably really easy to do but i am struggling

    Does anyone know how i can bind a string of xml that i create on the fly to a datagrid. I know how to do it using a xml file but i have no idea how to do it using a string of xml

    Any help would be fantastic

    Thanks

    Sarah

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    You have to put your string into a IO stream... then feed that to the ReadXML method of datast, plugging that into the DataGrid.

    VB Code:
    1. Imports System.IO
    2. Imports System.Text
    3.  
    4. Dim ioArray As Byte() = _
    5.             uniEncoding.GetBytes(xmlstring)
    6.  
    7. Dim memStream As New IO.MemoryStream
    8. memStream.Write(ioArray, 0 , ioArray.Length)
    9.  
    10. memStream.Seek(0, SeekOrigin.Begin)
    11. MyDataset.ReadXML(memStream)
    12.  
    13. MyDataGrid1.DataSource = MyDataSet

    From MSDN:
    Note
    If the XSD schema for a DataSet includes a targetNamespace, data may not be read, and you may encounter exceptions when calling ReadXml to load the DataSet with XML that contains elements with no qualifying namespace. To read unqualified elements, set elementFormDefault equal to "qualified" in your XSD schema as the following example demonstrates.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width