sqlstr="select *f rom a where c='12'"
如果这条语句查询不出结果.则查询
sqlstr="select *f rom a where like'12'"
这两个查询语句能不能合在一起呢?
是不是要两次调用数据库来查询.我的意思就是是不是要打开关闭两次数据库呢?
如果这条语句查询不出结果.则查询
sqlstr="select *f rom a where like'12'"
这两个查询语句能不能合在一起呢?
是不是要两次调用数据库来查询.我的意思就是是不是要打开关闭两次数据库呢?
sqlstr="select * from a where c like '%12%'"
这样得到的结果集包含
sqlstr="select *f rom a where c='12'"
的结果集,写这一句就可以了
没有任何占位符合等于没区别吧
sqlstr="select * from a where c like '%12'";//前匹配,匹配末尾为12的所有数据
sqlstr="select * from a where c like '12%'";//后匹配,匹配前端为12的所有数据
sqlstr="select * from a where c like '%12'";//全匹配,匹配含有12的所有数据sqlstr="select * from a where MID(c,1,2)='12'";//固定匹配,取字段前2个字符进行匹配,看是否为12
你要先查出C="12"
然后才能用like 查询
只要你两条语句之前没有对数据库执行conn.close().就没有打开关闭两次数据库,只是对已经打开的数据库进行两次查询。个人理解
sqlstrlike="select * from a where c like '%12%'"
SqlConnection connection = new SqlConnection(conn);
SqlCommand reader = new SqlCommand(sql, connection);
SqlDataReader sdr = reader.ExecuteReader();
if (sdr.HasRows)
{
....
}
else
{
reader.commandtext=sqlstrlike
sdr=reader.ExecuteReader();
}供你参考.
select * from a where c='%12%' //这句的意思是查询c中所有包含12的
select * from a where c='12%' /这句是所有前端包含12的楼主若想深入
请到我的资源里面去下载: http://download.csdn.net/source/448361(只要2分)
呵呵!