本帖最后由 foshanzhuifeng 于 2010-07-10 18:15:32 编辑

解决方案 »

  1.   

    m_pRecordset.CreateInstance(__uuidof(Recordset));  
      

  2.   


    返回值E_NOINTERFACE
    不支持此接口
      

  3.   

    void CVStarDataBaseToolDlg::OnBnClickedBtnModifydatabase()
    {
    m_pConnection.CreateInstance(__uuidof(Connection)); GetDlgItem(IDC_BTN_MODIFYDATABASE)->EnableWindow(false); if (0 != ConnectVStarDataBase())
    {
    AfxMessageBox(_T("连接VStar数据库失败!"));
    GetDlgItem(IDC_BTN_MODIFYDATABASE)->EnableWindow(true);
    m_pConnection = NULL;
    return;
    } if (0 != ExecuteModifyMission())
    {
    AfxMessageBox(_T("修改数据库失败!"));
    }
    else
    {
    AfxMessageBox(_T("修改数据库成功!"));
    } GetDlgItem(IDC_BTN_MODIFYDATABASE)->EnableWindow(true);
    m_pConnection->Close();
    m_pConnection = NULL;
    }int CVStarDataBaseToolDlg::ConnectVStarDataBase()
    {
    try
    {
    m_pConnection->Open("Driver={SQL Server};Server=(local)\\vstar;Database=vstar;Uid=sa;Pwd=;", "", "", adConnectUnspecified);
    }
    catch(_com_error e)
    {
    if (m_pConnection != NULL)
    {
    m_pConnection.Release();
    m_pConnection = NULL;
    }
    return 1;
    }
    catch(...)
    {
    if (m_pConnection != NULL)
    {
    m_pConnection.Release();
    m_pConnection = NULL;
    }
    return 1;
    } return 0;
    }int CVStarDataBaseToolDlg::ExecuteSQL(char* sql)
    {
    _variant_t RecordsAffected;
    try
    {
    m_pConnection->Execute(sql, &RecordsAffected, adCmdText);
    }
    catch(_com_error e)
    {
    //m_pConnection->Close();
    //m_pConnection.Release();
    //m_pConnection = NULL;
    return 1;
    }
    catch(...)
    {
    //m_pConnection->Close();
    //m_pConnection.Release();
    //m_pConnection = NULL;
    return 1;
    } return 0;
    }
    int CVStarDataBaseToolDlg::ExecuteModifyMission()
    {
    char* sql;
    sql = NULL; sql = "if not exists (select 1 from syscolumns where id=object_id('Channel') and name='RecordSound') \
    alter table Channel add RecordSound bit NULL";
    if (0 != ExecuteSQL(sql))
    {
    return 1;
    } return 0;
    }给你一段代码参考一下~
      

  4.   

    CVStarDataBaseToolDlg::ConnectVStarDataBase()//连接数据库
    CVStarDataBaseToolDlg::ExecuteSQL(char* sql)//执行SQL语句
      

  5.   

    我现在的问题是无法创建Connection对象,重新注册ADO也不行
    一、注册ADO:
            1.单击“开始”->“运行”
            2.输入 REGSVR32 "C:\Program Files\Common Files\System\ado\msado15.dll"
            3.单击“确定”按钮
      

  6.   

    从别的机器上拷个msado15过来重新注册下.
      

  7.   

    你要确认一下:在stdafx.h头文件中是否加上
    #import "C:\Program Files\common files\system\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
      

  8.   

    "ADODB.Connection "多了一个空格,问题解决了,thank you chenlycly AND zyq5945