locked
how to set a DataSet to read XML RRS feed

  • Question

  • The following sample will help to understand the problem I am having.

    I want to use an XML file in a combo drop down "C1.Win.C1List.C1Combo"

    Dim myXMLfile As String = "C:\Users\" & UserName() & "\AppData\Roaming\MyCompanyName\ASerchBy.xml"

    DSMnSrcBy.ReadXml(myXMLfile)

    With Me.SearchBy
                .Refresh()
                .DataSource = DSMnSrcBy.Tables("APrSearcBy")
                 .Splits(0).DisplayColumns("num").Visible = 0  

    I got a message "DataField or Caption not found" referring to  "Columns("num")"

    The following code is a copy of the XML file:

    <?xml version="1.0" encoding="UTF-8"?>
    <dataroot xmlns:od="urn:schemas-microsoft-com:officedata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:noNamespaceSchemaLocation="ASerchBy.xsd" generated="2018-11-22T11:49:05">
    <ASerchBy>
    <SearchBy>Company - Commercial</SearchBy>
    <num>25</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>Last Name, First, Company - Commercial</SearchBy>
    <num>26</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>First Name, Last, Company - Commercial</SearchBy>
    <num>27</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>Last Name, First - Residential</SearchBy>
    <num>28</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>First Name, Last - Residential</SearchBy>
    <num>29</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>Last Name, First</SearchBy>
    <num>30</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>First Name, Last</SearchBy>
    <num>31</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>Last, Spouse First</SearchBy>
    <num>33</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>Spouse First, Last</SearchBy>
    <num>34</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>Street, Number</SearchBy>
    <num>38</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>Number, Street</SearchBy>
    <num>41</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>Suite, Number, Street</SearchBy>
    <num>42</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>Tel</SearchBy>
    <num>50</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>Ac, Tel</SearchBy>
    <num>51</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>Additional Info</SearchBy>
    <num>60</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>Alt. Phone</SearchBy>
    <num>61</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>Company, Name-Spouse</SearchBy>
    <num>62</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>ID</SearchBy>
    <num>80</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>Code Id</SearchBy>
    <num>90</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>Group By, Classify, Code Id</SearchBy>
    <num>91</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>Classify, Group By, Code Id</SearchBy>
    <num>92</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>Date Begin, Department</SearchBy>
    <num>100</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>Date Begin, Department - Sort by Department</SearchBy>
    <num>105</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>Department, Date Begin</SearchBy>
    <num>110</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>Group By</SearchBy>
    <num>115</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>Classify</SearchBy>
    <num>116</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>Last Name, First, Balance</SearchBy>
    <num>120</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>Last Name, First, Sort by Balance</SearchBy>
    <num>130</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>Balance, Last Name, First</SearchBy>
    <num>140</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>Department - Date Begin, Name, Balance, Status</SearchBy>
    <num>150</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>Date Begin, Name, Balance, Status</SearchBy>
    <num>151</num>
    </ASerchBy>
    <ASerchBy>
    <SearchBy>Invoice Number</SearchBy>
    <num>160</num>
    </ASerchBy>
    </dataroot>
    

    Friday, January 4, 2019 3:41 PM

Answers

  • This works for me

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim ds As New DataSet
        Dim fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "xmlFile1.xml")
        ds.ReadXml(fileName)
        ComboBox1.DataSource = ds.Tables("ASerchBy")
        ComboBox1.DisplayMember = "num"
    End Sub


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by MosheS Singer Sunday, January 6, 2019 4:18 PM
    Friday, January 4, 2019 6:36 PM

All replies

  • Hi

    Your post doesn't make sense to me as there is no way for me to understand what you actually want.

    However, since you mention XML and ComboBox, I have put this together. This is just a stand alone example. You will need to edit the XML file 'path' variable to suit your own system. This sets up a ComboBox1 to list the 'num' as read from the XML file, and returns the 'SearchBy' value on selected item changed (puts into Label1.Text

    Now, I realize that this is NOT what you want, but if you try it out and post further information, maybe you will get what is needed.

    ' Form1 with ComboBox1 and
    ' Label1
    Option Strict On
    Option Explicit On
    Imports System.Xml
    Public Class Form1
      Dim path As String = "C:\Users\lesha\Desktop\Document.xml"
      Dim Searches As New List(Of Search)
      Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
    
        Dim doc As New XmlDocument()
        doc.Load(path)
    
        Dim nodes As XmlNodeList = doc.DocumentElement.SelectNodes("/dataroot/ASerchBy")
        For Each node As XmlNode In nodes
          Dim newSearch As New Search
          With newSearch
            .SearchBy = node.SelectSingleNode("SearchBy").InnerText
            .Num = CInt(node.SelectSingleNode("num").InnerText)
          End With
          Searches.Add(newSearch)
        Next
    
        With ComboBox1
          .DataSource = Searches
          .DisplayMember = "num"
          .ValueMember = "SearchBy"
          .DropDownStyle = ComboBoxStyle.DropDown
          .AutoCompleteMode = AutoCompleteMode.SuggestAppend
          .AutoCompleteSource = AutoCompleteSource.ListItems
        End With
      End Sub
      Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        Label1.Text = ComboBox1.SelectedValue.ToString
      End Sub
    End Class
    Class Search
      Property SearchBy As String
      Property Num As Integer
    End Class


    Regards Les, Livingston, Scotland


    • Edited by leshay Friday, January 4, 2019 4:25 PM
    Friday, January 4, 2019 4:25 PM
  • thanks i will try it and test your sample  Sunday
    Friday, January 4, 2019 5:01 PM
  • This works for me

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim ds As New DataSet
        Dim fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "xmlFile1.xml")
        ds.ReadXml(fileName)
        ComboBox1.DataSource = ds.Tables("ASerchBy")
        ComboBox1.DisplayMember = "num"
    End Sub


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by MosheS Singer Sunday, January 6, 2019 4:18 PM
    Friday, January 4, 2019 6:36 PM
  • Thanks a milion

    it works 

    i fixed the code an it works

    Sunday, January 6, 2019 4:19 PM