程序如下:
进入到该程序的时候,“vtFld = m_pRecordset->Fields->GetItem(lpFieldName)->Value;”就错在这句上了,后面的catch(_com_error &e)中e的m_pszMsg是“0x00000000 <错误的指针>"ado.cpp中:
BOOL CADORecordset::GetFieldValue(LPCTSTR lpFieldName, int& nValue)
{
int val = NULL;
_variant_t vtFld;
try
{
vtFld = m_pRecordset->Fields->GetItem(lpFieldName)->Value; //vtFld.vt = 1;
switch(vtFld.vt)
{
case VT_BOOL:
val = vtFld.boolVal;
break;
case VT_I2:
case VT_UI1:
val = vtFld.iVal;
break;
case VT_INT:
val = vtFld.intVal;
break;
case VT_NULL:
case VT_EMPTY:
val = 0;
break;
default:
val = vtFld.iVal;
}
nValue = val;
return TRUE;
}
catch(_com_error &e)
{
dump_com_error(e);
return FALSE;
}
}上面的函数是在这里的接口函数中调用:
adodb.cpp中
extern "C" __declspec(dllexport)
BOOL SelectAllPeople_CountFromDB(float& _CountValue)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState()); CString strSQL;
LPCTSTR AllPeopleCount = _T("box_id");
int CountValue;
CADORecordset myCADORecordset;
CADORecordset rs(&(theApp.m_Database));
#if 1
strSQL.Format("insert into current_info_table (user_age, user_sex, box_id, chan_info,\
prog_info, begin_time) values ('13-22岁','女 ','888888982','模拟频道95',\
'模拟频道95-2008-10-08 00:40:00','2008-10-08 00:40:00 ')");
#endif
strSQL.Format("select count(*) as box_id from current_info_table ");
theApp.m_Database.Execute(strSQL.GetBuffer(strSQL.GetLength()));
try
{
CADOCommand myCADOCommand( &(theApp.m_Database), strSQL, adCmdText);
//myCADORecordset.Execute(&myCADOCommand);
theApp.m_Database.Execute(strSQL.GetBuffer(strSQL.GetLength()));
myCADORecordset.GetFieldValue(AllPeopleCount,CountValue); }
catch(_com_error& e)
{
//dump_com_error(e);
return -1;
}
rs.Close();
_CountValue = (float)CountValue;
return 1;
} 弹出的框的错误提示是:
CADORecordset Error
Code= 800a0cc1
Code meaning = Unknown error 800a0cc1
Source =ADODB.Fields
Description = 在对应所需名称或序数的集合中,未找到项目。这样写是不是代码比较全了,大家帮忙看一下,是在不知道错误出在哪里了。
进入到该程序的时候,“vtFld = m_pRecordset->Fields->GetItem(lpFieldName)->Value;”就错在这句上了,后面的catch(_com_error &e)中e的m_pszMsg是“0x00000000 <错误的指针>"ado.cpp中:
BOOL CADORecordset::GetFieldValue(LPCTSTR lpFieldName, int& nValue)
{
int val = NULL;
_variant_t vtFld;
try
{
vtFld = m_pRecordset->Fields->GetItem(lpFieldName)->Value; //vtFld.vt = 1;
switch(vtFld.vt)
{
case VT_BOOL:
val = vtFld.boolVal;
break;
case VT_I2:
case VT_UI1:
val = vtFld.iVal;
break;
case VT_INT:
val = vtFld.intVal;
break;
case VT_NULL:
case VT_EMPTY:
val = 0;
break;
default:
val = vtFld.iVal;
}
nValue = val;
return TRUE;
}
catch(_com_error &e)
{
dump_com_error(e);
return FALSE;
}
}上面的函数是在这里的接口函数中调用:
adodb.cpp中
extern "C" __declspec(dllexport)
BOOL SelectAllPeople_CountFromDB(float& _CountValue)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState()); CString strSQL;
LPCTSTR AllPeopleCount = _T("box_id");
int CountValue;
CADORecordset myCADORecordset;
CADORecordset rs(&(theApp.m_Database));
#if 1
strSQL.Format("insert into current_info_table (user_age, user_sex, box_id, chan_info,\
prog_info, begin_time) values ('13-22岁','女 ','888888982','模拟频道95',\
'模拟频道95-2008-10-08 00:40:00','2008-10-08 00:40:00 ')");
#endif
strSQL.Format("select count(*) as box_id from current_info_table ");
theApp.m_Database.Execute(strSQL.GetBuffer(strSQL.GetLength()));
try
{
CADOCommand myCADOCommand( &(theApp.m_Database), strSQL, adCmdText);
//myCADORecordset.Execute(&myCADOCommand);
theApp.m_Database.Execute(strSQL.GetBuffer(strSQL.GetLength()));
myCADORecordset.GetFieldValue(AllPeopleCount,CountValue); }
catch(_com_error& e)
{
//dump_com_error(e);
return -1;
}
rs.Close();
_CountValue = (float)CountValue;
return 1;
} 弹出的框的错误提示是:
CADORecordset Error
Code= 800a0cc1
Code meaning = Unknown error 800a0cc1
Source =ADODB.Fields
Description = 在对应所需名称或序数的集合中,未找到项目。这样写是不是代码比较全了,大家帮忙看一下,是在不知道错误出在哪里了。
解决方案 »
- 发送的Http请求,服务器返回URL错误是怎么回事?
- 三国中的10个最强悍的无名小卒
- STL在CE下编译能通过,运行出错
- 如何利用二次开发工具包
- 在Windows下怎么将一个字符串输出成图形点阵格式的二进制串(单色的)
- 请教一个任务栏图标显示问题。
- 如何屏蔽和恢复鼠标消息,或者如何禁用鼠标和恢复,各位救我!
- 我要在VC程序中下载一个网上的文件保存到硬盘上,如HTTP://CSDN/downfile/be.jpg ,把be.jpg保存到硬盘,用什么实现好呢?
- <<Windows 程序设计(上、下)>> 怎么样?
- GetCursorPos的具体用法?? 本人不太懂,麻烦大家了!
- 关于mscomm控件串口通讯发送重复数据的问题,贴有代码,请指正
- 劳驾谁帮我看看这段代码哪里泄漏了
m_pRecordset->GetCollect("什么什么");
theApp.m_Database.Execute(strSQL.GetBuffer(strSQL.GetLength()));
myCADORecordset.GetFieldValue(AllPeopleCount,CountValue);
你只是使用【连接】对象执行了 SQL 语句;而【记录集】对象是空的,你去取一个空的记录集,所以出错了。
应该用【记录集对象】去打开这个 SQL 语句。
我猜测这个 myCADORecordset 提供了一个 Open 之类的成员函数,你看看。
theApp.m_Database.Execute(strSQL.GetBuffer(strSQL.GetLength()));
myCADORecordset.GetFieldValue(AllPeopleCount,CountValue); }
sql语句执行完了,没给myCADORecordset,
注意要大写 _T("BOX_ID");
BOOL CADORecordset::Execute(CADOCommand* pAdoCommand)
{
if(IsOpen())
Close(); ASSERT(!pAdoCommand->GetText().IsEmpty());
try
{
m_pConnection->CursorLocation = adUseClient; m_pRecordset = pAdoCommand->GetCommand()->Execute(NULL, NULL, pAdoCommand->GetType());
return TRUE;
}
catch(_com_error &e)
{
dump_com_error(e);
return FALSE;
}
}
e中错误提示是:
m_pszMsg 0x00000000 <错误的指针> char *弹出的框提示的是:
CADORecordset Error
Code= 80004003
Code meaning = 无效指针
Source =(null)
Description = (null)
下面的文章先认真看看吧!
【直接通过ADO操作Access数据库】http://www.vckbase.com/document/viewdoc/?id=496