我用的是Access数据库,如何进行数据的添加、修改、删除操作啊?

解决方案 »

  1.   

    AddNew(); //在表的末尾增加新记录
    Edit();   //修改
    Delete(); //删除
      

  2.   

    pRS1->AddNew();
    if(dlg.m_Name.IsEmpty())
    {
    AfxMessageBox("请嵌入姓名");return ;
    }
    pRS1->m_Address      =  dlg.m_Address;
    pRS1->m_EmailAddress =  dlg.m_Email;
    pRS1->m_HomePhone    =  dlg.m_hPhone;
    pRS1->m_MobilePhone  =  dlg.m_mPhone;
    pRS1->m_Notes        =  dlg.m_note;
    pRS1->m_WorkPhone    =  dlg.m_oPhone;
    pRS1->m_Name         =  dlg.m_Name; pRS1->Update();
    // refresh
    pRS1->Edit();
    pRS1->Update();
      

  3.   

    怎么样连接数据库呢?我用的是odbc
      

  4.   

    下面 的代码包括代码自动注册ocx 
    和用代码自动配置数据源还有怎样连接数据库,你自己看看吧
    不懂的地方可以给我留言.
    ////////////////////////////////////////////////////
    //手动注册*.Ocx控件
    CString str;
    ::GetCurrentDirectory(100,str.GetBuffer(100));
    str.ReleaseBuffer(); 
    HMODULE hModule;
    str+="\\Msflxgrd.ocx";
    HRESULT ret;
    hModule=::LoadLibrary(str);
    HRESULT (*DllRegisterServer)(void);
    DllRegisterServer=(HRESULT(*)(void))::GetProcAddress(hModule,"DllRegisterServer");
    if(DllRegisterServer)
    {
    ret=DllRegisterServer();
    if(ret!=S_OK)
    return FALSE;
    }
    ::FreeLibrary(hModule); //检查数据源是否注册,调用dll函数
    if(!CheckIfDataSourceInstalled("镜头库"))
    {
    //注册数据源
    CString strPath;
    GetModuleFileName(NULL,strPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH);
    strPath.ReleaseBuffer ();
    int nPos;
    nPos=strPath.ReverseFind ('\\');
    strPath=strPath.Left (nPos);
    CString strFile = strPath + "\\镜头库.mdb";//(这是你的数据库名吗?)

    //注册数据库 
    char* szDesc;
    int nlen;
    szDesc=new char[256];

    sprintf(szDesc,"DSN=%s? DESCRIPTION=TOC support source? DBQ=%s? FIL=MicrosoftAccess? DEFAULTDIR=%s?? ","镜头库",strFile,strPath);
    //去除结尾的回车符
    nlen = strlen(szDesc);
    for (int i=0; i<nlen; i++)
    {
    if (szDesc[i] == '?')
    szDesc[i] = '\0';
    } if (FALSE == SQLConfigDataSource(NULL,ODBC_ADD_DSN,"Microsoft Access Driver (*.mdb)\0",(LPCSTR)szDesc))
    AfxMessageBox("SQLConfigDataSource Failed");
    }