在Visual Basic中对数据集进行排序 [英] Sort a dataset in Visual Basic

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

问题描述

我不知道我做错了什么。我曾经在几个论坛上试图弄清楚如何在visual basic中对表格进行排序。

我已经对数据视图进行了调整,但注意到似乎有效。



我有一个用户可以进行新插入的日志。它有3列。 日期,工具,评论。

当我的VB应用程序加载程序时,从Access数据库中读取表格,并通过sql短语得到我的排序:

I don't know what i am doing wrong. I have been on several forums trying to figure out how to sort a table in visual basic.
I have treid with and with out a dataview, but noting seems to work.

I have a log that the user can do new inserts in. It has 3 columns. "Date", "Tool", "Comment".
When my VB application loads the program reads the table from a Access database and i get my sorting just fine by the sql phrase:

"select * from Logg ORDER BY Logg.Datum DESC"



用户对表格进行了更改后,我想再次对其进行排序。我已经畏缩了以下,但没有任何反应。无论我做什么,订单都是一样的。



DS是我的数据集,dw是我的数据视图,而Datum是我要排序的栏目


After a user have uppdated the table i whant to sort it again. I have treid the following, but nothing happens. The order is the same whatever i do.

DS is my Dataset and dw my dataview, and "Datum" the column i whant to sort

DS.Tables("hela").DefaultView.Sort = "Datum DESC"
dw = DS.Tables("hela").DefaultView
For i = 0 To antal_poss - 1
    LOGG(i, 0) = dw.Table.Rows(i).Item(3)
    LOGG(i, 1) = dw.Table.Rows(i).Item(1)
    LOGG(i, 2) = dw.Table.Rows(i).Item(4)
Next i



我做错了什么?请纠正我:(


What am i doing wrong?pls correct me:(

推荐答案

首先你很可能需要拨打DS .AcceptChanges()将更改保存回数据集。



然后使用片段循环记录。

First you most likely need to call DS.AcceptChanges() to save the changes back to your dataset.

Then use the snippet to loop through the records.
Using dw As New DataView(DS.Tables("hela"), "", "Datum DESC", DataViewRowState.CurrentRows)
    For Each oDrvItem As DataRowView In dw
        oDrvItem.Item(3)
        oDrvItem.Item(1)
        oDrvItem.Item(4)
    Next
End Using


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

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