VC访问数据库,作修改操作出现unhandled exception int ***怎么回事

解决方案 »

  1.   

    try之 输出错误代码看看 像这样
    http://msdn.microsoft.com/en-us/library/19b8k939(v=VS.80).aspx
    ODBC Exception Example
    The Open member function could throw an exception (of type CDBException for the ODBC classes), so this code brackets the Open call with a try block. The subsequent catch block will catch a CDBException. You could examine the exception object itself, called e, but in this case it is enough to know that the attempt to create a recordset has failed. The catch block displays a message box and cleans up by deleting the recordset object. CopyCRecordset* CSectionView::OnGetRecordset()
    {
        if ( m_pSet != NULL )
            return m_pSet;        // Recordset already allocated    m_pSet = new CSectionSet( NULL );
        try
        {
            m_pSet->Open( );
        }
        catch( CDBException* e )
        {
            AfxMessageBox( e->m_strError,   
                          MB_ICONEXCLAMATION );
            // Delete the incomplete recordset object
            delete m_pSet;
            m_pSet = NULL;
            e->Delete();
        }
        return m_pSet;
    }
    DAO Exception Example
    The DAO example is similar to the example for ODBC, but you can typically retrieve more kinds of information. The following code also attempts to open a recordset. If that attempt throws an exception, you can examine a data member of the exception object for error information. As with the previous ODBC example, it is probably enough to know that the attempt to create a recordset failed. CopyCDaoRecordset* CSectionView::OnGetRecordset()
    {
        if ( m_pSet != NULL )
            return m_pSet;  // Recordset already allocated    m_pSet = new CSectionSet( NULL );
        try
        {
            m_pSet->Open( );
        }
        catch( CDaoException* e )
        {
             AfxMessageBox( 
                    e->m_pErrorInfo->m_strDescription, 
                    MB_ICONEXCLAMATION );
            // Delete the incomplete recordset object
            delete m_pSet;
            m_pSet = NULL;
            e->Delete();
        }
        return m_pSet;
    }