使用odbc与数据库access连接,正常连接上了
现在想查找一下context字段的内容,但是查找的时候总是提示我说检索记录错误,找了不少的资料也没解决,请求这里的高人指导
另外连接数据库的时候,前面一个方法已经正常调用了,也能正常的取得数据,插入数据库,但是再一次取得的话,就不可以,请问是什么原因呢?代码如下:
CString strSQLselect=_T("");
USER_INF userInf;
CString strContext =_T(""); try{
strSQLselect.Format("Select * FROM chatcontext WHERE power = '%s' order by data_t desc","Student");
if(m_pSet->IsOpen())
m_pSet->Close();
m_pSet -> Open(CRecordset::dynaset,strSQLselect);
if(!(m_pSet->IsEOF())) // 从这里开始设置的断点,没有任何执行,但是m_pSet有值
{
m_pSet -> GetFieldValue("context",strContext); // get the value
strcpy(userInf.context,strContext);
} /// 到这里一直没有执行
}catch (CException *e){ // 直接跳到这里 执行了
TCHAR szError[1024];
e->GetErrorMessage(szError,1024);
::AfxMessageBox(szError);
}相反,一下代码可以正常执行,不明白原因,是我对于数据库操作的地方理解有问题 ? 请高人指教
CString strSQLselect=_T("");
CString strSQLinsert=_T("");
USER_INF userInf; strSQLselect.Format("Select * FROM userinfo WHERE id = %ld",m_nLocalId);
if(m_pSet->IsOpen())
m_pSet->Close();
m_pSet -> Open(CRecordset::dynaset,strSQLselect);
if(!(m_pSet->IsEOF()))
{
m_pSet -> GetFieldValue("power",strPower); // get the value
strcpy(userInf.power,strPower);
}
strSQLinsert.Format("insert into chatcontext(Localname,Targetname,context,data_t,power) values('%s','%s','%s','%s','%s')",
m_strLocalNickname,m_strTargetNickname,buff,str_time,userInf.power);
if (NULL != m_pSet)
{
if(m_pSet->IsOpen())
m_pSet->Close(); if ( !m_pSet->IsOpen()) // if the recordset isn't already open..
m_pSet->Open(CRecordset::dynaset,"select * from userinfo"); m_pSet->m_pDatabase->ExecuteSQL(strSQLinsert);
m_pSet->Close();
nRetVal = REGT_SUCCESS;
}
else{
AfxMessageBox("Data is NULL,please check the data!!!");
}
现在想查找一下context字段的内容,但是查找的时候总是提示我说检索记录错误,找了不少的资料也没解决,请求这里的高人指导
另外连接数据库的时候,前面一个方法已经正常调用了,也能正常的取得数据,插入数据库,但是再一次取得的话,就不可以,请问是什么原因呢?代码如下:
CString strSQLselect=_T("");
USER_INF userInf;
CString strContext =_T(""); try{
strSQLselect.Format("Select * FROM chatcontext WHERE power = '%s' order by data_t desc","Student");
if(m_pSet->IsOpen())
m_pSet->Close();
m_pSet -> Open(CRecordset::dynaset,strSQLselect);
if(!(m_pSet->IsEOF())) // 从这里开始设置的断点,没有任何执行,但是m_pSet有值
{
m_pSet -> GetFieldValue("context",strContext); // get the value
strcpy(userInf.context,strContext);
} /// 到这里一直没有执行
}catch (CException *e){ // 直接跳到这里 执行了
TCHAR szError[1024];
e->GetErrorMessage(szError,1024);
::AfxMessageBox(szError);
}相反,一下代码可以正常执行,不明白原因,是我对于数据库操作的地方理解有问题 ? 请高人指教
CString strSQLselect=_T("");
CString strSQLinsert=_T("");
USER_INF userInf; strSQLselect.Format("Select * FROM userinfo WHERE id = %ld",m_nLocalId);
if(m_pSet->IsOpen())
m_pSet->Close();
m_pSet -> Open(CRecordset::dynaset,strSQLselect);
if(!(m_pSet->IsEOF()))
{
m_pSet -> GetFieldValue("power",strPower); // get the value
strcpy(userInf.power,strPower);
}
strSQLinsert.Format("insert into chatcontext(Localname,Targetname,context,data_t,power) values('%s','%s','%s','%s','%s')",
m_strLocalNickname,m_strTargetNickname,buff,str_time,userInf.power);
if (NULL != m_pSet)
{
if(m_pSet->IsOpen())
m_pSet->Close(); if ( !m_pSet->IsOpen()) // if the recordset isn't already open..
m_pSet->Open(CRecordset::dynaset,"select * from userinfo"); m_pSet->m_pDatabase->ExecuteSQL(strSQLinsert);
m_pSet->Close();
nRetVal = REGT_SUCCESS;
}
else{
AfxMessageBox("Data is NULL,please check the data!!!");
}
解决方案 »
- 知道文本控件句柄,怎么判断控件是否有输入焦点??
- 请教折线平行等距线的算法。
- OpenGL中的旋转一问
- 那里有李维的《borland传奇》电子版的下载??
- 这是什么错误:missing storage-class or type specifiers ?
- 请问在VC++中怎样隐去原来写的字?
- 哪位大大有hough变换的源程序,最好是mfc的,帮忙发一个给我
- vs2010 安装失败 有什么办法解决吗?不重装系统
- 有谁知道fastdb的内存位图是怎么回事
- 选中ListCtrl的一项的事件是什么?LVN_????吗?
- IDispEventSimpleImpl 事件响应报错,程序终止!2天了还没有办法!
- 前台用VC6.0,后台用SQL SERVER2000,大侠们救命啊!!!
这句中的sql直接在数据库里能不能执行,在运行时打印出sql语句,放在数据库里看能否执行
if(!(m_pSet->IsEOF())) // 从这里开始设置的断点,没有任何执行,但是m_pSet有值
{
m_pSet -> GetFieldValue("context",strContext); // get the valuestrcpy(userInf.context,strContext);
} /// 到这里一直没有执行
}catch (CException *e){ // 直接跳到这里 执行了
....
}
以上if部分根本没有执行,直接就跳出执行catch的部分
试试看
你把单引号去掉应该才能检索到记录的