DataView.RowFilter的使用(包括in,like等SQL中的操作符)

DataView RowFilter Syntax [C#]
This example describes syntax of DataView.RowFil ter expression. It shows how to correctly build expression string (without „SQL injection“) using methods to escape values.

Column names
If a column name contains any of these special characters ~ ( ) # / / = > < + - * % & | ^ ' " [ ], you must enclose the column name within square brackets [ ]. If a column name contains right bracket ] or backslash /, escape it with backslash (/] or //).

[C#]

dataView.RowFilter = "id = 10"; // no special character in column name "id" dataView.RowFilter = "$id = 10"; // no special character in column name "$id" dataView.RowFilter = "[#id] = 10"; // special character "#" in column name "#id" dataView.RowFilter = "[[id/]] = 10"; // special characters in column name "[id]"
Literals
String values are enclosed within single quotes ' '. If the string contains single quote ', the quote must be doubled.

[C#]

dataView.RowFilter = "Name = 'John'" // string value dataView.RowFilter = "Name = 'John ''A'''" // string with single quotes "John 'A'" dataView.RowFilter = String.Format("Name = '{0}'", "John 'A'".Replace("'", "''"));
Number values are not enclosed within any characters. The values should be the same as is the result of int.ToString() or float.ToString() method for invariant or English culture.

[C#]

dataView.RowFilter = "Year = 2008" // integer value dataView.RowFilter = "Price = 1199.9" // float value dataView.RowFilter = String.Format(CultureInfo.InvariantCulture.NumberFormat, "Price = {0}", 1199.9f);
Date values are enclosed within sharp characters # #. The date format is the same as is the result of DateTime.ToString() method for invariant or English culture.

[C#]

dataView.RowFilter = "Date = #12/31/2008#" // date value (time is 00:00:00) dataView.RowFilter = "Date = #2008-12-31#" // also this format is supported dataView.RowFilter = "Date = #12/31/2008 16:44:58#" // date and time value dataView.RowFilter = String.Format(CultureInfo.InvariantCulture.DateTimeFormat, "Date = #{0}#", new DateTime(2008, 12, 31, 16, 44, 58));
Alternatively you can enclose all values within single quotes ' '. It means you can use string values for numbers or date time values. In this case the current culture is used to convert the string to the specific value.

[C#]

dataView.RowFilter = "Date = '12/31/2008 16:44:58'" // if current culture is English dataView.RowFilter = "Date = '31.12.2008 16:44:58'" // if current culture is German dataView.RowFilter = "Price = '1199.90'" // if current culture is English dataView.RowFilter = "Price = '1199,90'" // if current culture is German
Comparison operators
Equal, not equal, less, greater operators are used to include only values that suit to a comparison expression. You can use these operators = <> < <= > >=.

Note: String comparison is culture-sensitive, it uses CultureInfo from DataTable.Locale property of related table (dataView.Table.Locale). If the property is not explicitly set, its default value is DataSet.Locale (and its default value is current system culture Thread.Curren tThread.Curren tCulture).

[C#]

dataView.RowFilter = "Num = 10" // number is equal to 10 dataView.RowFilter = "Date < #1/1/2008#" // date is less than 1/1/2008 dataView.RowFilter = "Name <> 'John'" // string is not equal to 'John' dataView.RowFilter = "Name >= 'Jo'" // string comparison
Operator IN is used to include only values from the list. You can use the operator for all data types, such as numbers or strings.

[C#]

dataView.RowFilter = "Id IN (1, 2, 3)" // integer values dataView.RowFilter = "Price IN (1.0, 9.9, 11.5)" // float values dataView.RowFilter = "Name IN ('John', 'Jim', 'Tom')" // string values dataView.RowFilter = "Date IN (#12/31/2008#, #1/1/2009#)" // date time values dataView.RowFilter = "Id NOT IN (1, 2, 3)" // values not from the list
Operator LIKE is used to include only values that match a pattern with wildcards. Wildcard character is * or %, it can be at the beginning of a pattern '*value', at the end 'value*', or at both '*value*'. Wildcard in the middle of a patern 'va*lue' is not allowed.

[C#]

dataView.RowFilter = "Name LIKE 'j*'" // values that start with 'j' dataView.RowFilter = "Name LIKE '%jo%'" // values that contain 'jo' dataView.RowFilter = "Name NOT LIKE 'j*'" // values that don't start with 'j'
If a pattern in a LIKE clause contains any of these special characters * %

(0)

相关推荐

  • DataReader、DataSet、DataAdapter和DataView使用介绍

    ADO.NET提供两个对象用于检索关系型数据并把它存储在内存中,分别是DataSet和DataReader.DataSet提供内存中关系数据的表现--包括表和次序.约束等表间的关系的完整数据集合.DataReader提供快速.只向前.只读的来自数据库的数据流. 使用DataSet时,一般使用DataAdapter(也可能是CommandBuilder)与数据源交互,用DataView对DataSet中的数据进行排序和过滤.DataSet可以被继承来建立强化类型的DataSet,用于暴露表.行.列

  • Exitjs获取DataView中图片文件名

    1.前台 复制代码 代码如下: <script type="text/javascript" language="javascript"> function aa() { var selNode = this.DataView1.getSelectedNodes()[0]; alert( selNode.id); } </script> 2.后台 复制代码 代码如下: protected void Page_Load(object sende

  • jquery dataview数据视图插件使用方法

    jquery-dataview是一个超轻量的jquery插件,用于对DOM进行数据填充与更新,也很适合根据DOM模板创建对象. 与一些纯模板库(例如juicer)相比,它不仅能提供根据模板填入数据.支持循环.支持条件创建等功能,还支持绑定事件,最重要的是,在创建完DOM对象后,这些对象(称为数据视图)关联到原始数据,修改数据后,相应的视图也得以更新. 与一些支持数据驱动或MVVM模式的库(例如vue)相比,它没有去做数据绑定等高级自动化的机制,那涉及诸多复杂逻辑,比如属性依赖管理等,使用者如果了

  • winform导出dataviewgrid数据为excel的方法

    本文实例讲述了winform导出dataviewgrid数据为excel的方法.分享给大家供大家参考.具体实现方法如下: 复制代码 代码如下: #region 导出dataViewGrid视图中的数据为xls格式  private void btnExportList_Click(object sender, EventArgs e)  {     string fname = string.Empty; SaveFileDialog sfd = new SaveFileDialog(); sf

  • asp.net dataview做无限极分类的又一用法

    数据库结构: classidid 主键 jobClassName 对应的类型名称 ClassName 对应的父类的id 通常做法: 复制代码 代码如下: private void Display(string parentid, String space) { DataTable dt; String strSQL; strSQL = "Select * From Tree Where ParentID =" + parentid + " Order By ClassID D

  • DataView.RowFilter的使用(包括in,like等SQL中的操作符)

    DataView RowFilter Syntax [C#] This example describes syntax of DataView.RowFil ter expression. It shows how to correctly build expression string (without „SQL injection") using methods to escape values. Column names If a column name contains any of

  • Material(包括Material Icon)在Angular2中的使用详解

    1.引入material npm包 npm install @angular/material @angular/cdk 2.新建一个ebiz-material.module.ts方便管理引入material的module ng g module ebiz-material -app=ebiz-ui 3.在app的根module中引入ebiz-material.module.ts import { EbizMaterialModule } from './ebiz-material/ebiz-m

  • SpringBoot项目的logback日志配置(包括打印mybatis的sql语句)

    关于logback日志的详解见这位仁兄的博客:Spring Boot-日志配置(超详细) 我在这就开门见山直接介绍我们项目日志的配置使用吧!~ 1.基本介绍 默认情况下,Spring Boot项目就会用Logback来记录日志,并用INFO级别输出到控制台.如下图: 实际开发中我们不需要直接添加logback日志依赖. 你会发现 spring-boot-starter 其中包含了 spring-boot-starter-logging,该依赖内容就是 Spring Boot 默认的日志框架 lo

  • remote script文档(转载自微软)(七)

    文档: 检查错误 当您在服务器脚本中用 remote scripting 调用方法时,可能会遇到多种错误,包括语法错误和运行时间错误,以及调用 remote scripting 方法时的错误.remote scripting 调用机制向您提供了获知调用过程中所出现错误信息的途径. 错误处理程序根据您是进行同步或者异步调用稍微有些不一样.如果您在进行同步调用时导致错误,那么 remote scripting 机制将在浏览器中显示一条错误消息.错误文字来自于调用对象的 message 属性.有关详细

  • Oracle中游标Cursor基本用法详解

    查询 SELECT语句用于从数据库中查询数据,当在PL/SQL中使用SELECT语句时,要与INTO子句一起使用,查询的 返回值被赋予INTO子句中的变量,变量的声明是在DELCARE中.SELECT INTO语法如下: SELECT [DISTICT|ALL]{*|column[,column,...]} INTO (variable[,variable,...] |record) FROM {table|(sub-query)}[alias] WHERE............ PL/SQL

  • jquery $(document).ready() 与window.onload的区别

    1.执行时间 window.onload必须等到页面内包括图片的所有元素加载完毕后才能执行.         $(document).ready()是DOM结构绘制完毕后就执行,不必等到加载完毕. 2.编写个数不同 window.onload不能同时编写多个,如果有多个window.onload方法,只会执行一个          $(document).ready()可以同时编写多个,并且都可以得到执行 3.简化写法 window.onload没有简化写法          $(documen

  • spring+springmvc整合mabytis时mapper注入失败问题解决方法

    好久不搭架构,今天使用spring+springmvc整合mabytis的时候,坑爹的两个问题发生了. 花了一晚上解决这两个问题.现在将错误经验总结分享下,避免以后遇到坑继续往里跳. 1. 单元测试的时候,单元测试失败报错: A ServletContext is required to configure default servlet handling 十月 28, 2016 9:03:33 下午 org.springframework.context.support.GenericAppl

  • ORACLE SQL语句优化技术要点解析

    操作符优化: IN 操作符 用IN写出来的SQL的优点是比较容易写及清晰易懂,这比较适合现代软件开发的风格. 但是用IN的SQL性能总是比较低的,从ORACLE执行的步骤来分析用IN的SQL与不用IN的SQL有以下区别: ORACLE试图将其转换成多个表的连接,如果转换不成功则先执行IN里面的子查询,再查询外层的表记录,如果转换成功则直接采用多个表的连接方式查询. 由此可见用IN的SQL至少多了一个转换的过程.一般的SQL都可以转换成功,但对于含有分组统计等方面的SQL就不能转换了. 推荐方案:

  • 手把手编写PHP框架 深入了解MVC运行流程

    1 什么是MVC MVC模式(Model-View-Controller)是软件工程中的一种软件架构模式,把软件系统分为三个基本部分:模型(Model).视图(View)和控制器(Controller). PHP中MVC模式也称Web MVC,从上世纪70年代进化而来.MVC的目的是实现一种动态的程序设计,便于后续对程序的修改和扩展简化,并且使程序某一部分的重复利用成为可能.除 此之外,此模式通过对复杂度的简化,使程序结构更加直观.软件系统通过对自身基本部份分离的同时,也赋予了各个基本部分应有的

  • SqlParser 一个利用正则表达式解析单句SQL的类

    先看要解析的样例SQL语句: 复制代码 代码如下: select * from dual SELECT * frOm dual Select C1,c2 From tb select c1,c2 from tb select count(*) from t1 select c1,c2,c3 from t1 where condi1=1 Select c1,c2,c3 From t1 Where condi1=1 select c1,c2,c3 from t1,t2 where condi3=3

随机推荐