DataView.RowFilter的使用(包括in,like等SQL中的操作符)
DataViewRowFilterSyntax[C#]
ThisexampledescribessyntaxofDataView.RowFilterexpression.Itshowshowtocorrectlybuildexpressionstring(without„SQLinjection“)usingmethodstoescapevalues.
Columnnames
Ifacolumnnamecontainsanyofthesespecialcharacters~()#//=><+-*%&|^""[],youmustenclosethecolumnnamewithinsquarebrackets[].Ifacolumnnamecontainsrightbracket]orbackslash/,escapeitwithbackslash(/]or//).
[C#]
dataView.RowFilter="id=10";//nospecialcharacterincolumnname"id"dataView.RowFilter="$id=10";//nospecialcharacterincolumnname"$id"dataView.RowFilter="[#id]=10";//specialcharacter"#"incolumnname"#id"dataView.RowFilter="[[id/]]=10";//specialcharactersincolumnname"[id]"
Literals
Stringvaluesareenclosedwithinsinglequotes"".Ifthestringcontainssinglequote",thequotemustbedoubled.
[C#]
dataView.RowFilter="Name="John""//stringvaluedataView.RowFilter="Name="John""A""""//stringwithsinglequotes"John"A""dataView.RowFilter=String.Format("Name="{0}"","John"A"".Replace(""",""""));
Numbervaluesarenotenclosedwithinanycharacters.Thevaluesshouldbethesameasistheresultofint.ToString()orfloat.ToString()methodforinvariantorEnglishculture.
[C#]
dataView.RowFilter="Year=2008"//integervaluedataView.RowFilter="Price=1199.9"//floatvaluedataView.RowFilter=String.Format(CultureInfo.InvariantCulture.NumberFormat,"Price={0}",1199.9f);
Datevaluesareenclosedwithinsharpcharacters##.ThedateformatisthesameasistheresultofDateTime.ToString()methodforinvariantorEnglishculture.
[C#]
dataView.RowFilter="Date=#12/31/2008#"//datevalue(timeis00:00:00)dataView.RowFilter="Date=#2008-12-31#"//alsothisformatissupporteddataView.RowFilter="Date=#12/31/200816:44:58#"//dateandtimevaluedataView.RowFilter=String.Format(CultureInfo.InvariantCulture.DateTimeFormat,"Date=#{0}#",newDateTime(2008,12,31,16,44,58));
Alternativelyyoucanencloseallvalueswithinsinglequotes"".Itmeansyoucanusestringvaluesfornumbersordatetimevalues.Inthiscasethecurrentcultureisusedtoconvertthestringtothespecificvalue.
[C#]
dataView.RowFilter="Date="12/31/200816:44:58""//ifcurrentcultureisEnglishdataView.RowFilter="Date="31.12.200816:44:58""//ifcurrentcultureisGermandataView.RowFilter="Price="1199.90""//ifcurrentcultureisEnglishdataView.RowFilter="Price="1199,90""//ifcurrentcultureisGerman
Comparisonoperators
Equal,notequal,less,greateroperatorsareusedtoincludeonlyvaluesthatsuittoacomparisonexpression.Youcanusetheseoperators=<><<=>>=.
Note:Stringcomparisonisculture-sensitive,itusesCultureInfofromDataTable.Localepropertyofrelatedtable(dataView.Table.Locale).Ifthepropertyisnotexplicitlyset,itsdefaultvalueisDataSet.Locale(anditsdefaultvalueiscurrentsystemcultureThread.CurrentThread.CurrentCulture).
[C#]
dataView.RowFilter="Num=10"//numberisequalto10dataView.RowFilter="Date<#1/1/2008#"//dateislessthan1/1/2008dataView.RowFilter="Name<>"John""//stringisnotequalto"John"dataView.RowFilter="Name>="Jo""//stringcomparison
OperatorINisusedtoincludeonlyvaluesfromthelist.Youcanusetheoperatorforalldatatypes,suchasnumbersorstrings.
[C#]
dataView.RowFilter="IdIN(1,2,3)"//integervaluesdataView.RowFilter="PriceIN(1.0,9.9,11.5)"//floatvaluesdataView.RowFilter="NameIN("John","Jim","Tom")"//stringvaluesdataView.RowFilter="DateIN(#12/31/2008#,#1/1/2009#)"//datetimevaluesdataView.RowFilter="IdNOTIN(1,2,3)"//valuesnotfromthelist
OperatorLIKEisusedtoincludeonlyvaluesthatmatchapatternwithwildcards.Wildcardcharacteris*or%,itcanbeatthebeginningofapattern"*value",attheend"value*",oratboth"*value*".Wildcardinthemiddleofapatern"va*lue"isnotallowed.
[C#]
dataView.RowFilter="NameLIKE"j*""//valuesthatstartwith"j"dataView.RowFilter="NameLIKE"%jo%""//valuesthatcontain"jo"dataView.RowFilter="NameNOTLIKE"j*""//valuesthatdon"tstartwith"j"
IfapatterninaLIKEclausecontainsanyofthesespecialcharacters*%
相关文章
- 通过Burp使用DNS协作器进行的带外SQL攻击
- SQL开发知识:Oracle cursor 游标的使用详解
- in Neo4j查询:使用Not In操作(neo4j查询not)
- Oracle 视图 V$SQL_WORKAREA 官方解释,作用,如何使用详细说明
- 标题:使用Oracle 查询 SQL 语句(oracle查sql)
- MySQL中使用IN子查询的技巧(mysql子查询in)
- sql develperMac上使用Oracle SQL Developer的指南(mac版oracle)
- 如何使用MySQL导出SQL语句?(mysql导出sql语句)
- SQL Server中括号的使用方法详解(sqlserver括号)
- 数据合法性使用SQL语句判断MSSQL数据合法性(sql判断mssql)
- 如何使用MySQL定时自动执行SQL语句(mysql定时执行sql)
- 使用SQL Server编译器提升数据库性能(sqlserver编译器)
- 类型使用SQL Server实数类型算出精确结果(sqlserver实数)
- 如何使用 MySQL 还原 SQL 数据库备份文件?(mysql还原sql)
- 使用SQL Server 2008中文版 打开软件开发新时代(sqlserver2008中文版)
- MySQL中IN运算符的使用技巧(mysql中 与in)
- 中的数据使用SQL从Redis中检索数据(使用sql获取redis)
- Oracle中IN运算符的强大用法(oracle中in的使用)
- 查询Oracle中使用IN关键字查询多个值的方法(oracle中in多个值)
- Oracle IN一种SQL语句查询的高效方式(oracle in的定义)
- Oracle 中的 IN 子句使用技巧(oracle in 子句)
- sql字符串函数大全和使用方法示例