VB.NET 2010 Express Dataset/Dataview 的 XML 问题
我是一名学习 vb.net 的合作学生,我有一个项目,该项目从程序内的 xml 文件检索数据(基于组合框的选择)并计算和显示价格。
我的 XML 如下所示:
<.根>
....<.进程>
........<.进程>12345<./进程>
........<.12345Material_Process>此流程<./12345Material_Process>
........<.率>20<./率>
........<.类型>氮气<./类型>
........<.直径>0.125<./直径>
.
.
.
...<./进程>
....<.机器>
........<.机器>AB12345
........<.Machine_Type>12345 4000 <./Machine_Type>
........<.AB12345Bed_Size>4000<./AB12345Bed_Size>
........<.基本价格>$831.00<./基本价格>
.
.
.
....<./机器>
<./根>
*句点用于显示(无法弄清楚如何显示 xml 代码,我对代码很陌生!)
我有一个组合框可以很好地从“进程”部分加载数据,但另一个组合框使用相同的方法并获得“ IndexOutOfRange”错误或“未找到列 AB12345Bed_Size”,即使我对两者使用相同的方法。对于“流程”,我在“<12345Material_Process>”上使用 DataView.Sort它反映了组合框中的选定项目。程序毫无问题地检索该行。 这是给我带来问题的代码:
将 xmlFile 调暗为 XmlReader xmlFile = XmlReader.Create("File.xml", New XmlReaderSettings()) Dim ds 作为新数据集 将 dv 调暗为 DataView ds.ReadXml(xmlFile) dv = 新数据视图(ds.Tables(0)) dv.Sort = strName & “床_尺寸” Dim 索引 As Integer = dv.Find(cmbSize.SelectedItem)
我已阅读 msdn 并尝试理解它,并搜索了许多论坛和示例。
非常感谢任何帮助。
I am a co-op student learning vb.net and I have a project which retrieves data from an xml file within the program (based on selections made from combo boxes) and calculates and displays prices.
My XML looks like this:
<.Root>
....<.Processes>
........<.Process>12345<./Process >
........<.12345Material_Process>This Process<./12345Material_Process >
........<.Rate>20<./Rate >
........<.Type>Nitrogen<./Type >
........<.Dia>0.125<./Dia >
.
.
.
...<./Processes>
....<.Machines>
........<.Machine>AB12345
........<.Machine_Type>12345 4000 <./Machine_Type >
........<.AB12345Bed_Size>4000<./AB12345Bed_Size >
........<.Base_Price>$831.00<./Base_Price >
.
.
.
....<./Machines>
<./Root>
*Periods are for display (Couldn't figure out how to display xml code, I am that new with code!)
I have one combobox that loads data from the Processes section just fine, but then another uses the same method and gets an "IndexOutOfRange" error or "Column AB12345Bed_Size Not Found" even though I am using the same method for both. For "Processes" I am using DataView.Sort on "<12345Material_Process>" which reflects the selecteditem in the combobox. The program retrieves that row without a problem.
Here is the code that is giving me a problem:
Dim xmlFile As XmlReader xmlFile = XmlReader.Create("File.xml", New XmlReaderSettings()) Dim ds As New DataSet Dim dv As DataView ds.ReadXml(xmlFile) dv = New DataView(ds.Tables(0)) dv.Sort = strName & "Bed_Size" Dim index As Integer = dv.Find(cmbSize.SelectedItem)
I have read msdn and tried to make sense of it, as well as searching through many forums and examples.
Any help is GREATLY appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
显然我不太了解 XML。我将其重命名为“<.Machines>”标记为“<.Processes>”现在可以了。现在想起来我以前也遇到过类似的问题。
所以我想我最好尽早报名参加下学期的 XML 课程!
So obviously I don't know XML very well. I renamed the "<.Machines>" tags as "<.Processes>" and now it works. Now that I think about it I had a similar problem before.
So I guess I'd better sign up early for that XML class next term!