我想根据变量来控制查询的条件,请问该怎么做!!!!
我的如下方法<1>
char buf[256];
m_pSet.CreateInstance(__uuidof(Recordset));
CString FieldName,str;
FieldName = .....;
str = ...........;
sprintf(buf,"select * from booklist where %s = %s",FieldNmame,str);
m_pSet->Open(_variant_t(buf),m_pConn.GetInterfacePtr(),
<2>
_RecordsetPtr pRst(__uuidof(Recordset));
CString strSql="select * from password";
CString strTemp=" where num = ";
strSql+=strTemp;
strSql+=num;
// AfxMessageBox(strSql);
BSTR bstrSQL = strSql.AllocSysString();
m_pSet->Open(bstrSQL,(IDispatch*)m_pConn,adOpenDynamic,adLockOptimistic,
adCmdText);
以前的程序中实现过类似的查询,但是由于中毒,程序都丢失了,也记不清当时是怎么具体实现的了,现在用到以上方法,用MessageBox 看Sql语句正常,可是程序在调试运行时到m_pSet->Open()时提示Unhandle excetion。Kernel32.dll 什么什么的,不知是为什么,请路过的大侠指导一下!!!不盛感激!!
我的如下方法<1>
char buf[256];
m_pSet.CreateInstance(__uuidof(Recordset));
CString FieldName,str;
FieldName = .....;
str = ...........;
sprintf(buf,"select * from booklist where %s = %s",FieldNmame,str);
m_pSet->Open(_variant_t(buf),m_pConn.GetInterfacePtr(),
<2>
_RecordsetPtr pRst(__uuidof(Recordset));
CString strSql="select * from password";
CString strTemp=" where num = ";
strSql+=strTemp;
strSql+=num;
// AfxMessageBox(strSql);
BSTR bstrSQL = strSql.AllocSysString();
m_pSet->Open(bstrSQL,(IDispatch*)m_pConn,adOpenDynamic,adLockOptimistic,
adCmdText);
以前的程序中实现过类似的查询,但是由于中毒,程序都丢失了,也记不清当时是怎么具体实现的了,现在用到以上方法,用MessageBox 看Sql语句正常,可是程序在调试运行时到m_pSet->Open()时提示Unhandle excetion。Kernel32.dll 什么什么的,不知是为什么,请路过的大侠指导一下!!!不盛感激!!
{...
}catch(_com_exception ee)
{
MessageBox(ee.ErrorMessage());
}
看看m_pSet, m_pConn是否有效.