本文转自: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. es6 babel 安装以及使用

    1,安装好node(需要使用npm包管理工具) 2,在本地项目路径下npm init,格式化成功后会在项目下生成一个配置文件package.json 3,本地安装bable npm install - ...

  2. CocoaPods 详解之----更新篇

    CocoaPods 大概是 2011 年出现的开源组件管理工具(目前已支持 Objective-C 和 Swift),近年来普及率越来越高,几乎已是所有 Cocoa 开源项目的标配.另外,很多大点的团 ...

  3. 2018 ICPC南京网络赛 Set(字典树 + 合并 + lazy更新)

    题解:n个集合,你要进行m个操作.总共有3种操作.第一种,合并两个集合x和y.第二张,把特定的集合里面所有的数字加一.第三种,询问在某个集合里面,对于所有数字对2的k次方取模后,有多少个数字等于x. ...

  4. 洛谷P2569 (BZOJ1855)[SCOI2010]股票交易 【单调队列优化DP】

    Description 最近lxhgww又迷上了投资股票,通过一段时间的观察和学习,他总结出了股票行情的一些规律. 通过一段时间的观察,lxhgww预测到了未来T天内某只股票的走势,第i天的股票买入价 ...

  5. AtCoder-3920

    We have a 3×3 grid. A number ci,j is written in the square (i,j), where (i,j) denotes the square at ...

  6. Mysql多实例数据库

    什么是Mysql的多实例? 简单的说,Mysql多实例就是一台服务器上同时开启多个不同的服务端口(如3306.3307)同时运行多个Mysql服务进程,这些服务进程通过不同socket监听不同的服务端 ...

  7. MySql数据库之子查询和高级应用

    MySql数据库中的子查询: 子查询:在一条select查询语句中嵌套另一条select语句,其主要作用是充当查询条件或确定数据源. 代码案例如下: 例1. 查询大于平均年龄的学生: select * ...

  8. 使用@babel/preset-typescript取代awesome-typescript-loader和ts-loader

    前言 之前写过一篇旧React项目升级使用TypeScript的文章:在React旧项目中安装并使用TypeScript的实践. 博客里使用awesome-typescript-loader对Type ...

  9. 【docker】Dockerfile

    [docker]Dockerfile 转载: ============================================================= =============== ...

  10. C# 中获取一个目录下的目录与文件

    //获得目录下所有文件和子目录使用DirectoryInfo类的GetFileSystemInfos()方法. //获得目录下所有目录 string[] dirs = Directory.GetDir ...