程序如下:
进入到该程序的时候,“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 = 在对应所需名称或序数的集合中,未找到项目。这样写是不是代码比较全了,大家帮忙看一下,是在不知道错误出在哪里了。

解决方案 »

  1.   

    你那用法本人是第一次见到。
    m_pRecordset->GetCollect("什么什么");
      

  2.   


    theApp.m_Database.Execute(strSQL.GetBuffer(strSQL.GetLength())); 
    myCADORecordset.GetFieldValue(AllPeopleCount,CountValue);
    你只是使用【连接】对象执行了 SQL 语句;而【记录集】对象是空的,你去取一个空的记录集,所以出错了。
    应该用【记录集对象】去打开这个 SQL 语句。
    我猜测这个 myCADORecordset 提供了一个 Open 之类的成员函数,你看看。
      

  3.   

    //myCADORecordset.Execute(&myCADOCommand);   --- 怎么注释了
    theApp.m_Database.Execute(strSQL.GetBuffer(strSQL.GetLength()));
    myCADORecordset.GetFieldValue(AllPeopleCount,CountValue); } 
    sql语句执行完了,没给myCADORecordset,
      

  4.   

    LPCTSTR AllPeopleCount = _T("box_id");
    注意要大写 _T("BOX_ID");
      

  5.   

    注掉是因为打开是有问题的。程序会到红的区域后,跳到error。
    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)
      

  6.   

    3楼的意思是除了connect之外数据库中并没有数据库,还要insert数据库吗??
      

  7.   

    楼主,你这代码是从哪里拷贝来的,原理还没有理解吧?
    下面的文章先认真看看吧!
    【直接通过ADO操作Access数据库】http://www.vckbase.com/document/viewdoc/?id=496
      

  8.   

    数据库是sql server的。我先看看去,如果哪位大侠能有比较简单易懂的步骤希望可以给我。
      

  9.   

    你给我的这个是access的而且是静态链接的吧?不太明啊