Access数据库模糊查询

Access数据库模糊查询,第1张

sql.Format("select * from tb_user where 用户名 = '%s' or 用户名 like '%[%]s%*' ",m_Find,m_Find)

或者

sql.Format("select * from tb_user where 用户名 = '%s' or 用户名 like '%[%s]%*' ",m_Find,m_Find)

试试

使用"like"进行模糊查询,在access查询视图中要使用"*"做模糊匹配(sql中是"%").

在access数据库中调试用"*",程序中要改过来用"%",否则是查询不到任何数据的

try

{

_strSql=""

if (dataGridView1.Rows.Count <= 1)

{

if (dataGridView1.Rows[0].Cells[0].Value == null || dataGridView1.Rows[0].Cells[1].Value == null || dataGridView1.Rows[0].Cells[2].Value == null)

{

return

}

else

{

string filed = GetArrayElement(Cxzd, dataGridView1.Rows[0].Cells[0].Value.ToString().Trim(), 1)

//string type = GetArrayElement(Cxzd, filed, 2)

string cs = Cxfs[dataGridView1.Rows[0].Cells[1].Value.ToString().Trim()].ToString()

string content = dataGridView1.Rows[0].Cells[2].Value.ToString()

if (cs == "like")

{

content = "'%" + content + "%'"

}

_strSql = string.Format("where {0} {1} {2} ", filed, cs, content)

}

}

Select * from [人员信息表] where [工号] like '0001*'

如果用Access软件的话,like '001*'

用程序,比如ASP,的话 like '001%'

Access有点坑爹,搞两套通配符。

001*的意思是以001开头的

也可以是 *001* 这就是包含001的。

看你的需要去写了。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/sjk/6770497.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-28
下一篇 2023-03-28

发表评论

登录后才能评论

评论列表(0条)

保存