模糊查询

来源:百度知道 编辑:UC知道 时间:2024/06/01 16:39:00
select* from Employe where Employe_Name like '%w% ' 这样只是查出名字里面有W的人,想请教下如果我想随便输入什么就可以查出什么
'%w% '要换成什么啊???
我是这么写着,但是报错
CString strname,sql;
m_name.GetWindowText(strname);
sql.Format("select * from View_Purchase where Employe_Name like '%%s%' ",strcode);
m_pRecordset.CreateInstance(_uuidof(Recordset));
dlg.m_pRecordset->Open((_bstr_t )sql,dlg.m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
我用的是SQL数据库+ADO代码连接+VC6.0
View_Purchase 改为Employe

随便输入什么就可以查出什么 那就不用条件了,直接select* from Employe

try this:

CString sql,sqla, sqlb;

sqla = _T("select * from View_Purchase where Employe_Name like '%");
sqlb.Format(_T("%s"),strcode);

sql = sqla+sqlb+_T("%'");

//MFC's format function doesn't recognise "'%%s%'"
//you need to seperate them