Fehler beim schreiben auf MS-Access Datenbank mittels OleDb



  • Hallo, ich habe ein Access-Datenbank mit einen Primärschlüssel gesetzt auf (Auto)Increment.

    CTable<CDynamicAccessor> rs; 
    
    CDBPropSet propset(DBPROPSET_ROWSET); 
    propset.AddProperty(DBPROP_IRowsetChange, true); 
    propset.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE | DBPROPVAL_UP_INSERT | DBPROPVAL_UP_DELETE); 
    
    HRESULT hr=rs.Open(session, szTableName, &propset, 1); 
    //hr is ok 
    
    bool bRet; 
    bRet=rs.SetStatus((ULONG)1, DBSTATUS_S_ISNULL);  //primärschlüssel 
    UINT val=2; 
    bRet=rs.SetValue(((ULONG)2, (UINT*)val);         //setze col=2 
    
    hr=rs.Insert();                                   
    if(FAILED(hr)) 
    { 
      // kein fehler aber DB_S_ERRORSOCCURRED 
    } 
    
    //Ergebnis DB_S_ERRORSOCCURRED, schauen wir mal 
    
    //An error occurred while returning data for one or more columns, 
    //but data was successfully returned for at least one column 
    
    DBSTATUS status; 
    rs.GetStatus(((ULONG)0, &status);          //DBSTATUS_E_INTEGRITYVIOLATION 
    rs.GetStatus(((ULONG)1, &status);          //DBSTATUS_E_INTEGRITYVIOLATION  
    C/C++ Code: 
    CTable<CDynamicAccessor> rs; 
    
    CDBPropSet propset(DBPROPSET_ROWSET); 
    propset.AddProperty(DBPROP_IRowsetChange, true); 
    propset.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE | DBPROPVAL_UP_INSERT | DBPROPVAL_UP_DELETE); 
    
    HRESULT hr=rs.Open(session, szTableName, &propset, 1); 
    //hr is ok 
    
    bool bRet; 
    bRet=rs.SetStatus((ULONG)1, DBSTATUS_S_ISNULL); //primärschlüssel 
    UINT val=2; 
    bRet=rs.SetValue(((ULONG)2, (UINT*)val); //setze col=2 
    
    hr=rs.Insert(); 
    if(FAILED(hr)) 
    { 
    // kein fehler aber DB_S_ERRORSOCCURRED 
    } 
    
    //Ergebnis DB_S_ERRORSOCCURRED, schauen wir mal 
    
    //An error occurred while returning data for one or more columns, 
    //but data was successfully returned for at least one column 
    
    DBSTATUS status; 
    rs.GetStatus(((ULONG)0, &status); //DBSTATUS_E_INTEGRITYVIOLATION 
    rs.GetStatus(((ULONG)1, &status); //DBSTATUS_E_INTEGRITYVIOLATION  
    C/C++ Code: 
    CTable<CDynamicAccessor> rs; 
    
    CDBPropSet propset(DBPROPSET_ROWSET); 
    propset.AddProperty(DBPROP_IRowsetChange, true); 
    propset.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE | DBPROPVAL_UP_INSERT | DBPROPVAL_UP_DELETE); 
    
    HRESULT hr=rs.Open(session, szTableName, &propset, 1); 
    //hr is ok 
    
    bool bRet; 
    bRet=rs.SetStatus((ULONG)1, DBSTATUS_S_ISNULL);  //primärschlüssel 
    UINT val=2; 
    bRet=rs.SetValue(((ULONG)2, (UINT*)val);         //setze col=2 
    
    hr=rs.Insert();                                   
    if(FAILED(hr)) 
    { 
      // kein fehler aber DB_S_ERRORSOCCURRED 
    } 
    
    //Ergebnis DB_S_ERRORSOCCURRED, schauen wir mal 
    
    //An error occurred while returning data for one or more columns, 
    //but data was successfully returned for at least one column 
    
    DBSTATUS status; 
    rs.GetStatus(((ULONG)0, &status);          //DBSTATUS_E_INTEGRITYVIOLATION 
    rs.GetStatus(((ULONG)1, &status);          //DBSTATUS_E_INTEGRITYVIOLATION
    

    Die Daten werden ordnungsgemäß geschrieben und der Primärschlüssel (Auto)
    Inrement wir auf einen neuen Wert gesetzt.

    Meine Frage was ist DBSTATUS_E_INTEGRITYVIOLATION "The data value violated an integrity constraint"
    (das ist schon klar??) aber wie kann ich diese Fehlermeldung vermeiden.

    Eigendlich sollte das Ergebnis S_OK sein.

    Hat jemand von euch eine Idee?

    Volker



  • Dieser Thread wurde von Moderator/in HumeSikkins aus dem Forum C++ in das Forum MFC mit dem Visual C++ verschoben.

    Im Zweifelsfall bitte auch folgende Hinweise beachten:
    C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?

    Dieses Posting wurde automatisch erzeugt.



  • Danke da stand ich schon drin. übrigens verwende ich WTL !!!

    volker


Anmelden zum Antworten