在dao.net中我们通常都是使用到通配符过滤来进行查询数据,用到的是单字符匹配和多字符匹配。
通配符过滤使用的是like。
单字符匹配的通配符为半下划线"_",表示它能匹配单个的任意字符。
例如:
select * from Employee where Name like "_ames"; //这句话就表示以任意一个字符开头,剩余部分是"ames"。
多字符匹配的通配符为半角百分号"%",它能匹配任意次数(零或多个)出现的任意字符。
例如:
select * from Employee where Name like "%a%"; //这句sql语句它能检索出姓名中包含有n字的所有名字。
多值匹配可以用or来分隔,也可以用in来处理。介于某个值之间可以用betwee....and用法。
例如:
select * from Employee where age=20 or age=30 or age=40
或者 select * from Employee where age in(20,30,40)
betwee....and
select * from Employee where age between 20 and 30
ado.net中的null与c#中的null值不一样。ado.net中的null值表示"不知道",而不是表示为空;c#中的给变量赋值为null,就表示为”空“。假如我们想要查询姓名字段为null中的值,我们要用(select * from Employee where Name is null),而不是(select * from Employee where Name=null)。假如我们想要查询姓名查询名字不为null,我们要用(select * from Employee where Name is not null),而不是(select * from Employee where Name<>null)。
---------------------- Windows Phone 7手机开发、 .Net培训、期待与您交流! ----------------------