extern CString strText;
m_pRecordset->Open("SELECT * FROM UserTbl Where Name like '%" + strText + "%'", // 查询DemoTable表中所有字段
m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
为啥出错呢。
m_pRecordset->Open("SELECT * FROM UserTbl Where Name like '%" + strText + "%'", // 查询DemoTable表中所有字段
m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
为啥出错呢。
2)把其中的SQL语句放到“查询管理器”运行看有没有错。
3)注意 ' " 号的写法。
m_pRecordset->Open("SELECT * FROM UserTbl Where Name like '\%"+ strText +"\%'", // 查询DemoTable表中所有字段
m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);还是一样出错。
提示如下:
2 IntelliSense: 没有与这些操作数匹配的 "+" 运算符
"SELECT * FROM UserTbl Where Name like '12345'"这样写的话,没有错误。
要先搞成CString才能+
可以查看http://msdn.microsoft.com/en-us/library/k74e1xsh.aspx
如果要这样格式化,可以定义一个临时的CString,再格式化字符串。
CString cstr;
cstr.Format("SELECT * FROM UserTbl Where Name like '\%%s\%'", strText);
或者用sprintf也可以。
_RecordsetPtr m_pRecordset=NULL;
strSQL.Format("SELECT * from XXTable WHERE XXID = '%s'",strXXID);m_pRecordset->Open(_variant_t(strSQL), m_pConnect.GetInterfacePtr(), adOpenForwardOnly,adLockReadOnly, adCmdText);
VC6+ADO一直可以以上这样写
这样OK.