[转]VB.NET DataTable Select Function
本文转自: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的更多相关文章
- Datatable的查找和排序(Datatable.Select)
Datatable 是一种常用的数据结构.数据类型有点类似于数据库中的表结构.在没有使用优秀的orm框架前,大部分的数据库的数据都是先变为Datatable 然后再通过代码转换变成 object. ...
- 在DataTable中执行DataTable.Select("条件")返回DataTable;
转:http://blog.csdn.net/hcf_force/article/details/7779062 1.在DataTable中执行DataTable.Select("条件&qu ...
- DataTable.select() 返回 DataTable
DataTable.select() 默认返回值为 DataRow[]数组 代码来自网络: /**/ /// <summary> /// 执行DataTable中的查询返回新的DataTa ...
- DataTable.Select
转载请注明出处:http://www.cnblogs.com/havedream/p/4453297.html 方法:DataTable.Select 作用:获取 DataRow 对象的数组. 重载: ...
- 项目中遇到的 linq datatable select
1如何使用DataTable.Select选出来的Rows生成新的DataTable?DataTable dt = 数据源;DataTable dtt = new DataTable();dtt=dt ...
- C# DataTable.Select() 筛选数据
有时候我们需要对数据表进行筛选,微软为我们封装了一个公共方法, DataTable.Select(),其用法如下: Select() Select(string filterExpression) S ...
- 在DataTable中执行DataTable.Select("条件")
.在DataTable中执行DataTable.Select("条件")返回DataTable: // <summary> // 执行DataTable中的查询返回 ...
- DataSource绑定DataTable.Select()显示system.data.DataRow问题解决的方法
有时候我们须要在控件中绑定DataTable中设定条件过滤后的数据,此时,在winForm环境中,一些控件不能正确绑定并显示数据内容.这是由于DataTable.Select()返回的是DataRow ...
- [datatable]关于在DataTable中执行DataTable.Select("条件")返回DataTable的解决方法
-- :09关于在DataTable中执行DataTable.Select("条件")返回DataTable的解决方法 在实际编程工程中,常常遇到这样的情况:DataTable并不 ...
随机推荐
- 工作流Activity组件值数据传递获取问题
如图:先简单说一下大致过程 通过具体的菜单节点,加载具体的指令组件.本着低耦合的原件,需要将核查组件从指令组件重拆分出来,作为单独的组件根据业务需要拖拽到指令组件中.但是具体业务方面核查组件一方面需要 ...
- 基于 SOA 架构,创建 ego-search-web 项目-solr集群-zookeeper集群
项目架构 Ego-search-web 服务的消费者,ego-rpc 服务提供者 建立 ego-search-web 项目 继承:ego 依赖:ego-common ego-rpc-service ...
- JavaScript基础3
While循环 在指定条件为真时循环执行代码块.先确定条件再执行代码 语法 while(条件) { 需要执行的代码 } 条件中所用变量如果没有值,循环就不会停下,会导致浏览器崩溃: do...whil ...
- 第一节:Shiro HelloWorld 实现
1.新建maven工程,pom配置maven jar包 <dependency> <groupId>org.apache.shiro</groupId> <a ...
- MyBatis系列(四) MyBatis 增删改
前言 通过前几张的博文已经知道MyBatis是如何查询数据库中的数据,现在来介绍增(insert)删(delete)改(update) 增加 接口绑定文件定义一个增加方法,方法的返回值为long,在M ...
- 快速掌握zabbix配置
有人说zabbix难点在配置,面对很多的配置项,不知道所以然了,其实我觉得这是没掌握好zabbix的学习方法,要掌握了zabbix的学习思路,可以在一个小时内快速掌握zabbix的各种配置,下面我将重 ...
- css修改overflow滚动条默认样式
html代码 <div class="inner"> <div class="innerbox"> <p style=" ...
- 【spring boot】配置信息
======================================================================== 1.feign 超时配置 2.上传文件大小控制 3.J ...
- Java类中static的用法
关于Java中static的使用有以下四种情况: 1.静态成员变量 被static修饰的成员变量,叫静态成员变量或类变量:没有被static修饰的变量,叫实例变量. 两者的区别是: ...
- NodeJS2-3环境&调试----module.exports与exports的区别
exports默认会给他设置为module.exports的快捷方式,可以把它的里面添加属性,但是我们不能修改它的指向,如果修改了它的指向那它和普通对象没有任何区别了.因为在CommonJS中,模块对 ...