先前发过一个帖子,得到某一字段的最大奇偶数,SQL语句这么写
select max(col) from TB where col%2=0 ---偶数
select max(col) from TB where col%2=0 ---奇数
在SQL-Server 查询分析器中运行也是正确的。
但是我在我的MFC程序中断点调试这个语句就是执行不过
代码片段如下:
CString tablename = "test";
strSQL = "SELECT MAX(里程) FROM " + tablename + " WHERE 里程%2=0";
m_pCommand ->CommandText = (LPCSTR)_bstr_t(strSQL);
m_pRecordset = m_pCommand ->Execute(NULL, NULL, adCmdText);断点设在最后一行,运行不过去。
这是为啥子呢????
在VC中执行SQL语句,到底用什么方式比较好呢?
select max(col) from TB where col%2=0 ---偶数
select max(col) from TB where col%2=0 ---奇数
在SQL-Server 查询分析器中运行也是正确的。
但是我在我的MFC程序中断点调试这个语句就是执行不过
代码片段如下:
CString tablename = "test";
strSQL = "SELECT MAX(里程) FROM " + tablename + " WHERE 里程%2=0";
m_pCommand ->CommandText = (LPCSTR)_bstr_t(strSQL);
m_pRecordset = m_pCommand ->Execute(NULL, NULL, adCmdText);断点设在最后一行,运行不过去。
这是为啥子呢????
在VC中执行SQL语句,到底用什么方式比较好呢?
pRecordset->Open((_bstr_t)strSQL ,_variant_t((IDispatch*)pConnection,true),
adOpenDynamic,adLockOptimistic,adCmdUnspecified);
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pCommand->ActiveConnection = m_pConnection;
都有吧?
::CoInitialize(NULL);
select max(col) from TB where col%2=0 ---偶数
select max(col) from TB where col%2=1 ---奇数
你0和1都分写错了??
m_pCommand ->CommandText = (LPCSTR)_bstr_t(strSQL);
m_pRecordset = m_pCommand ->Execute(NULL, NULL, adCmdText);