请先看我的代码:
CString m_sID = "%";
_variant_t strQuery;
strQuery = "select * from MyTable where ID like '"+m_sID+"' ";我原以为可以查找到ID为任何值的记录,可是查不到ID为空的记录。
请问我的代码要怎样改才查找到该属性为空的记录?谢谢!
CString m_sID = "%";
_variant_t strQuery;
strQuery = "select * from MyTable where ID like '"+m_sID+"' ";我原以为可以查找到ID为任何值的记录,可是查不到ID为空的记录。
请问我的代码要怎样改才查找到该属性为空的记录?谢谢!
select * from MyTable
strQuery.Format("select * from MyTable where ID like '%%abc%%'"); //两个%才可以
就会将所有含有abc的记录查找出来
if (!m_bPhoneNumberCheck) m_sPhoneNumber = "%";
if (!m_bNumberStateCheck) m_sNumberState = "%";
if (!m_bCustomerNameCheck) m_sCustomerName = "%";
if (!m_bIllustrationCheck) m_sIllustration = "%";
if (!m_bLimitCheck) m_sLimit = "%";
_variant_t strQuery;
strQuery = "select * from phone_Info where PhoneNumber like '"+m_sPhoneNumber+"' and NumberState like '"+m_sNumberState+"' and CustomerName like '"+m_sCustomerName+"' and Illustration like '"+m_sIllustration+"' and Limit like '"+m_sLimit+"'";
strQuery = "select * from phone_Info where 1=1 "
if (m_bPhoneNumberCheck)
{
Temp.Format(" and m_sPhoneNumber = 's%'", YourValue);
strQuery += Temp;
}
其他的条件类似处理
strQuery.Format("select * from %s where %s = %s",strTableName,strColName,strValue);
我原来也用
strQuery = "select * from MyTable where ID like '"+m_sID+"' ";
不过也是好像不行。你不行就换这种方法拉。
error C2676: binary '+=' : 'class _variant_t' does not define this operator or a conversion to a type acceptable to the predefined operator
前面的定义是:
CString Temp;
_variant_t strQuery;
error C2371: 'strQuery' : redefinition; different basic types
CString Temp;
CString strQuery;//组装strQuery//在使用的地方如果需要再进行转换,如:
m_pRecordset->Open(_variant_t(strQuery),
_variant_t((IDispatch *)pMyConnect,true), adOpenKeyset,
adLockOptimistic, adCmdStoredProc);
感谢jnxulei(石头)感谢jacking007(复活岛)感谢你们大家!!!
该是什么呢?是Temp.Format(" and PhoneNumber like %s'", m_sPhoneNumber);吗?
因为在*.Format("")中使用%s替换,1.你的第二条少一个但引号and PhoneNumber like '%s'",
2.另外在字符串中要替换出SQL语句的“%”要在C++环境中使用成"%%"代表一个"%",而要表示SQL里的"LIKE 'temp%'"在C++中是*.Format("%s%%",temp)。3.如果你的m_sPhoneNumber是int型,那么用LIKE 合适么,我没有时间试一下。