本文转自: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. TC297B - 外设头文件解析(以IO为例)

    打开例程,目录树下的Includes中包含了各个片上资源对应的头文件,这些头文件定义了相应外设的寄存器地址(寄存器是内置于各个 IP 外设中,是一种用于配置外设功能的存储器,就是一种内存,并且有相对应 ...

  2. swift实现单例的四种方式

    单例模式 单例模式是设计模式中最简单的一种,甚至有些模式大师都不称其为模式,称其为一种实现技巧,因为设计模式讲究对象之间的关系的抽象,而单例模式只有自己一个对象. 当你只需要一个实例的时候需要使用单例 ...

  3. SpringBoot系列之JDBC数据访问

    SpringBoot系列之JDBC数据访问 New->Project or Module->Spring Initializer 选择JDBC和mysql驱动,为了方便测试web等等也可以 ...

  4. 笔记||Python3之函数

    函数:          函数的概念:就是一段代码:一段操作流程. 优点:代码量少.简洁.   维护起来方便 -- 在函数的定义进行修改 函数的定义:1 - def 函数名(): 函数内容 2 - 函 ...

  5. 8月份21道最新Java面试题剖析(数据库+JVM+微服务+高并发)

    前言 纵观几年来的Java面试题,你会发现每家都差不多.你仔细观察就会发现,HashMap的出现几率未免也太高了吧!连考察的知识点都一样,什么hash碰撞啊,并发问题啊!再比如JVM,无外乎考内存结构 ...

  6. 【朝花夕拾】Android多线程之(三)runOnUiThread篇——程序猿们的贴心小棉袄

    runOnUiThread()的使用以及原理实在是太简单了,简单到笔者开始都懒得单独开一篇文章来写它.当然这里说的简单,是针对对Handler比较熟悉的童鞋而言的.不过麻雀虽小,五脏俱全,runOnU ...

  7. 曹工说Spring Boot源码(3)-- 手动注册Bean Definition不比游戏好玩吗,我们来试一下

    写在前面的话 相关背景及资源: 曹工说Spring Boot源码系列开讲了(1)-- Bean Definition到底是什么,附spring思维导图分享 工程代码地址 思维导图地址 工程结构图: 大 ...

  8. 《Java基础知识》Java static关键字以及Java静态变量和静态方法

    static 修饰符能够与变量.方法一起使用,表示是“静态”的. 静态变量和静态方法能够通过类名来访问,不需要创建一个类的对象来访问该类的静态成员,所以static修饰的成员又称作类变量和类方法.静态 ...

  9. 《Java基础知识》Java类的定义及其实例化

    类必须先定义才能使用.类是创建对象的模板,创建对象也叫类的实例化. 下面通过一个简单的例子来理解Java中类的定义: public class Dog { String name; int age; ...

  10. 从头实现一个WPF条形图

    时间如流水,只能流去不流回! 点赞再看,养成习惯,这是您给我创作的动力! 本文 Dotnet9 https://dotnet9.com 已收录,站长乐于分享dotnet相关技术,比如Winform.W ...