2012-06-20 40 views
1

我在Visual Basic 2010上有點新手,並且想創建一個聊天加載器,並且我希望它從xml表中讀取值。試圖從Xml文件中讀取DataSet以將值添加到組合框中

這是我在Vb中使用的代碼。

ChatXml.ReadXmlSchema(My.Application.Info.DirectoryPath & "/../Release/chat.xml") 
ChatXml.ReadXml(My.Application.Info.DirectoryPath & "/../Release/chat.xml") 
ComboBox1.DataSource = ChatXml.Tables 
ComboBox1.DisplayMember = "chat" 

和xml文件。

<?xml version="1.0" encoding="utf-8"?> 
<chat> 
    <gn>Help</gn> 
    <gid>1913106</gid> 
    <xc>2336</xc> 
    <cn>1500337760</cn> 
    <g8>g8</g8> 
</chat> 

,我想它做的,是閱讀的價值「GN」,並將其添加到組合框,我不知道什麼是錯的,試圖「谷歌是你的朋友」,但沒有找到有用的東西。

我得到的錯誤是這樣的。

Complex DataBinding accepts as a data source either an IList or an IListSource. 
enter code here 

不確定,但試圖將數據添加到DataSet中的表,但似乎我無法讓它工作。 有什麼幫助嗎?

回答

2

您的問題是,您正在指示組合框顯示聊天表中的所有行,而不是讓它顯示聊天表中的所有gn字段。您需要這樣做:

ComboBox1.DataSource = ChatXml.Tables(0) 
ComboBox1.DisplayMember = "gn" 
相關問題