如何使用xml对数据集进行排序 [英] How to sort dataset with xml

查看:61
本文介绍了如何使用xml对数据集进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个xml文件,并尝试加载到datagridview中,按desc排序后如何保存xml?

Hi
I have an xml file and try to load into datagridview, how can I save the xml after I sort it by desc?

DS.ReadXml(Application.StartupPath & "\user.xml")
       Dim DS As New DataSet
       If DS.Tables(0).Rows.Count = 0 Then
           MsgBox("nothing")
       Else
           Dim i As Integer = 0
           For Each r As DataRow In DS.Tables(0).Rows
               dtgUser.Rows.Insert(i, r("ID"), r("Name"))
               i = i + 1
           Next
       End If
       dtgUser.Sort(dtgUser.Columns("ID"), System.ComponentModel.ListSortDirection.Ascending)





Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
           
        DS.WriteXml(Application.StartupPath & "\user.xml")
            
    End Sub





推荐答案

首先,您需要了解变量范围 [此处 [
First of all you need to understand Scope of variables[^]
And here[^] you''ll find complete example (ReadXml & WriteXml).


在保存到xml文件之前应该对表进行排序:

You should sort the table before save to xml file:

Dim dv As New Dataview(DS.Tables(0))
dv.Sort="ID DESC"
DS.Tables(0)=dv.ToTable


这篇关于如何使用xml对数据集进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆