本文转自:https://www.dotnetperls.com/datatable-select-vbnet

VB.NET DataTable Select Function
This VB.NET example program uses the DataTable type and its Select Function. Select searches for matching rows with a query.
DataTable Select. A DataTable stores rows and columns. It is a container of other data. But it also provides search functionality. With the Select method, we query a DataTable for rows that match a condition.
DataTable Example. This program first creates a DataTable with the name "Players." It then adds two columns—each row will store a "Size" and "Sex" value. We call Rows.Add five times to populate the collection with data. Then: We call the DataTable Select Function. This returns an array of DataRow instances.
DataRow Query: We use the query (Size >= AND Sex = "m"). So only data rows with a Size greater than and a Sex of "m" are returned.
VB.NET program that uses DataTable, Select Module Module1 Sub Main()
' Create a table.
Dim table As DataTable = New DataTable("Players") ' Add two columns.
table.Columns.Add(New DataColumn("Size", GetType(Integer)))
table.Columns.Add(New DataColumn("Sex", GetType(Char))) ' Add five rows.
table.Rows.Add(, "f"c)
table.Rows.Add(, "f"c)
table.Rows.Add(, "m"c)
table.Rows.Add(, "m"c)
table.Rows.Add(, "m"c) ' Get players above 230 size with "m" sex.
Dim result() As DataRow = table.Select("Size >= 230 AND Sex = 'm'") ' Loop and display.
For Each row As DataRow In result
Console.WriteLine("{0}, {1}", row(), row())
Next
End Sub End Module Output , m
, m
DateTime. Next, we use the Select Function with a DateTime. We create a new DataTable storing Widget model information. We populate it with three rows. These contain the ID of the widget and the DateTime the widget was built. Then: We pass the query string containing a DateTime substring to the Select Function. Note: For using a DateTime query, we can use the numeric comparison operators. We must surround the date with pound "#" symbols.
VB.NET program that uses Select, date Module Module1 Sub Main()
' Create a table.
Dim table As DataTable = New DataTable("Widgets") ' Add two columns.
table.Columns.Add(New DataColumn("ID", GetType(Integer)))
table.Columns.Add(New DataColumn("Date", GetType(DateTime))) ' Add rows.
table.Rows.Add(, New DateTime(, , ))
table.Rows.Add(, New DateTime(, , ))
table.Rows.Add(, New DateTime(, , )) ' Get rows more recent than 6/1/2001.
Dim result() As DataRow = table.Select("Date > #6/1/2001#") ' Loop.
For Each row As DataRow In result
Console.WriteLine(row())
Next
End Sub End Module Output Or. In the examples, we have seen the "AND" operator. We have also done numeric comparisons and date comparisons. Another supported operator for Select is the "OR" operator. This operator is used in the same way as in an SQL query. Summary. A DataTable is more than a container for data objects. It provides functionality that helps you search for matching rows. The syntax is like that of an SQL query. But no database is ever opened or used. © - Sam Allen. Every person is special and unique. Send bug reports to info@dotnetperls.com.
Home
Search
Home
Dot Net Perls

[转]VB.NET DataTable Select Function的更多相关文章

  1. Datatable的查找和排序(Datatable.Select)

    Datatable  是一种常用的数据结构.数据类型有点类似于数据库中的表结构.在没有使用优秀的orm框架前,大部分的数据库的数据都是先变为Datatable 然后再通过代码转换变成 object. ...

  2. 在DataTable中执行DataTable.Select("条件")返回DataTable;

    转:http://blog.csdn.net/hcf_force/article/details/7779062 1.在DataTable中执行DataTable.Select("条件&qu ...

  3. DataTable.select() 返回 DataTable

    DataTable.select() 默认返回值为 DataRow[]数组 代码来自网络: /**/ /// <summary> /// 执行DataTable中的查询返回新的DataTa ...

  4. DataTable.Select

    转载请注明出处:http://www.cnblogs.com/havedream/p/4453297.html 方法:DataTable.Select 作用:获取 DataRow 对象的数组. 重载: ...

  5. 项目中遇到的 linq datatable select

    1如何使用DataTable.Select选出来的Rows生成新的DataTable?DataTable dt = 数据源;DataTable dtt = new DataTable();dtt=dt ...

  6. C# DataTable.Select() 筛选数据

    有时候我们需要对数据表进行筛选,微软为我们封装了一个公共方法, DataTable.Select(),其用法如下: Select() Select(string filterExpression) S ...

  7. 在DataTable中执行DataTable.Select("条件")

     .在DataTable中执行DataTable.Select("条件")返回DataTable:  // <summary> // 执行DataTable中的查询返回 ...

  8. DataSource绑定DataTable.Select()显示system.data.DataRow问题解决的方法

    有时候我们须要在控件中绑定DataTable中设定条件过滤后的数据,此时,在winForm环境中,一些控件不能正确绑定并显示数据内容.这是由于DataTable.Select()返回的是DataRow ...

  9. [datatable]关于在DataTable中执行DataTable.Select("条件")返回DataTable的解决方法

    -- :09关于在DataTable中执行DataTable.Select("条件")返回DataTable的解决方法 在实际编程工程中,常常遇到这样的情况:DataTable并不 ...

随机推荐

  1. 洛谷 题解 P3173 【[HAOI2009]巧克力】

    本蒟蒻又双叒叕被爆踩辣! 又是一道经典的贪心题: 那么怎样切割该块巧克力,花费的代价最少呢? Solution: 窝们考虑每个状态,有多少种选择方法? 是不是可以选择横着切或者竖着切,就这两种方法吧: ...

  2. Bless You Autocorrect!

    题目链接: https://odzkskevi.qnssl.com/0c87453efec2747f8e8a573525fd42f9?v=1533651456 题解: 这是一道Trie+BFS的题目: ...

  3. 【译】Visual Studio 2019 中 WPF & UWP 的 XAML 开发工具新特性

    原文 | Dmitry 翻译 | 郑子铭 自Visual Studio 2019推出以来,我们为使用WPF或UWP桌面应用程序的XAML开发人员发布了许多新功能.在本周的 Visual Studio ...

  4. zabbix监控系统系列

    来自网站:http://www.361way.com/zabbix-summarize/3335.html 一.zabbix的特点 zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能 ...

  5. ARTS-S docker ceontos镜像中使用crontab

    centos镜像中默认没有crontab,需要在dockerflle中通过yum的安装 yum -y install vixie-cron crontabs && yum clean ...

  6. JAVA中SPI机制

    之前研究dubbo的时候就很好奇,里面各种扩展机制,期间也看过很多关于SPI的机制,今日有缘再度看到有文章总结,故记录一下, 首先了解一下 JAVA中SPI简单的用法 可参考这篇文章,https:// ...

  7. layim手机版嵌入app

    感觉记忆力不行了,才做了就有点忘了.先简单做下记录... 遇到的问题 需要类似微信的语音发送功能 前端发送给后端,在mogodb中用二进制存储.后端取到数据发送给我的也是blob.前端拿到数据就变了. ...

  8. redis(6)--redis集群之分片机制(redis-cluster)

    Redis-Cluster 即使是使用哨兵,此时的Redis集群的每个数据库依然存有集群中的所有数据,从而导致集群的总数据存储量受限于可用存储内存最小的节点,形成了木桶效应.而因为Redis是基于内存 ...

  9. angular6路由参数的传递与获取

    1.访问路由链接:/test/id 路由配置: {path: 'test/:id', component: TestComponent} html传参: <a href="javasc ...

  10. python学习-for

    # 对字典的遍历. key-value# dict_my = {"class":"python17","goal":"翻倍&quo ...