BOOL CFenKuangDlg::OnInitDialog()
{
CDialog::OnInitDialog();
    
int i;
CString  m_kming;
    try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
CXGSApp *pApp=(CXGSApp *)AfxGetApp();
ASSERT_VALID(pApp);    
m_pRecordset->Open("SELECT * FROM 粉矿综合性能",_variant_t((IDispatch*)theApp.m_pConnectSQL,true),adOpenStatic,adLockOptimistic,adCmdText);   //AfxMessageBox("1");
m_pRecordset->MoveFirst(); for(i=1;i<=m_pRecordset->GetRecordCount();i++)
{
m_kming=(char *)(_bstr_t)m_pRecordset->GetCollect("矿物名称");
m_kuangming.AddString((LPCTSTR)m_kming);
m_pRecordset->Update();
m_pRecordset->MoveNext();


m_pRecordset->Close();

}
catch(_com_error e)///捕捉异常
{

CString str;
str.Format("读取粉矿综合性能表失败!\r\n错误信息:%s!",e.ErrorMessage());///显示错误信息
AfxMessageBox(str);
return false;
}

m_bNewUser = FALSE; //初始化记录集对象
    m_pRecordset1.CreateInstance("ADODB.Recordset");    //打开记录集
    HRESULT hr = m_pRecordset1->Open("SELECT * FROM 粉矿综合性能",_variant_t((IDispatch*)theApp.m_pConnectSQL,true), adOpenDynamic, adLockPessimistic, adCmdText);    //如果打开记录集成功,则读取当前记录
    if(SUCCEEDED(hr))    {
      //读取当前记录
        ReadData();
    }   //根据当前记录的位置,重置各个控件的有效性    ResetControls(); //UpdateData(false);
return true;
}这样读数据,弹出读取表失败,错误信息是:无效指针。
逐步运行后,几个局部变量的值是这样的,我看不懂
hInstance        0x00400000 {unused=9460301 }       HINSTANCE__ *
    unused      9460301                         int
hPrevInstance   0x00000000 {unused=??? }       HINSTANCE__ *
    unused      CXX0030: 错误: 无法计算表达式的值   int
lpCmdLine       0x00141f0c ""                char *
       0                                   char
nCmdShow        1                                   int哪位能帮我解释一下,拜求了!

解决方案 »

  1.   

    断点调试一下,在哪里挂了?连接数据库了没?
      

  2.   

    谢谢,我的问题解决了。
    我的代码是没错的,是数据库里面出现问题了。列名跟代码不一致导致的
      

  3.   

    数据库列名与代码不一致,会直接导致出错,可编译但肯定是运行不了的。
      

  4.   

    很多人最先做数据库 容易出错就在后台与前台数据类型的不匹配 
    而你是直接属性名就不同 更厉害!!汗.........
      

  5.   

    呵呵,给进来看的人也提个醒呀,代码中读取数据的名称与数据库中的列名一定要仔细对照写